On this page
tokenize.TokenInfo
Prev: tokenize.TokenError | Up: tokenize | Next: tokenize.tokenize
Rel: tokenize.detect_encoding, tokenize.generate_tokens, tokenize.open, tokenize.TokenError
Ref: docs.python.org — tokenize.TokenInfo
Tags: #public #python3 #stdlib #tokenize
Import
import tokenize
from tokenize import TokenInfo
Signature & Overview
tokenize.TokenInfo(type, string, start, end, line)
tokenize.TokenInfo class.
Methods & Attributes
TokenInfo.count(self, value, /)— Return number of occurrences of value.TokenInfo.exact_type(...)—TokenInfo.exact_typemethod/property.TokenInfo.index(self, value, start=0, stop=9223372036854775807, /)— Return first index of value.
Usage
import io, tokenize
tok = next(tokenize.generate_tokens(io.StringIO('x = 1').readline))
assert isinstance(tok, tokenize.TokenInfo) and tok.string == 'x'
Gotchas
- Use
tok.exact_typeto distinguish specific operators (EQUAL,PLUS,LPAR) whentok.type == token.OP.
REPL Inspect
from tokenize import TokenInfo
help(TokenInfo)
Linked from
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/TokenError 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 links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/tokenize/untokenize shared tags: #stdlib, #tokenize
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib