On this page
tokenize.TokenError
Prev: tokenize.open | Up: tokenize | Next: tokenize.TokenInfo
Rel: tokenize.detect_encoding, tokenize.generate_tokens, tokenize.open, tokenize.TokenInfo
Ref: docs.python.org โ tokenize.TokenError
Tags: #public #python3 #stdlib #tokenize
Import
import tokenize
from tokenize import TokenError
Signature & Overview
tokenize.TokenError(...)
tokenize.TokenError class.
Methods & Attributes
TokenError.add_note(self, note, /)โ Add a note to the exceptionTokenError.with_traceback(self, tb, /)โ Set self.traceback to tb and return self.
Usage
import io, tokenize
try:
list(tokenize.generate_tokens(io.StringIO('x = (1 + 2').readline))
except tokenize.TokenError:
assert True
Gotchas
- Raised on unclosed brackets, quotes, or multi-line strings.
REPL Inspect
from tokenize import TokenError
help(TokenError)
Linked from
- tuts/python3/stdlib_module/tokenize
- tuts/python3/stdlib_module/tokenize/detect_encoding
- tuts/python3/stdlib_module/tokenize/generate_tokens
- tuts/python3/stdlib_module/tokenize/open
- tuts/python3/stdlib_module/tokenize/TokenInfo
- tuts/python3/stdlib_module/tokenize/tokenize
- tuts/python3/stdlib_module/tokenize/untokenize
Related notes
- tuts/python3/stdlib_module/tokenize/detect_encoding Linked here; links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/generate_tokens Linked here; links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/open Linked here; links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/TokenInfo Linked here; links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/tokenize Linked here; links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/untokenize links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib