On this page
tokenize.untokenize
Prev: tokenize.tokenize | Up: tokenize
Rel: tokenize.detect_encoding, tokenize.generate_tokens, tokenize.open, tokenize.TokenError
Ref: docs.python.org — tokenize.untokenize
Tags: #public #python3 #stdlib #tokenize
Import
import tokenize
from tokenize import untokenize
Signature & Overview
tokenize.untokenize(iterable)
Transform tokens back into Python source code.
Usage
import io, tokenize
src = 'x = 1 + 2\n'
toks = list(tokenize.generate_tokens(io.StringIO(src).readline))
assert tokenize.untokenize(toks) == src
Gotchas
- Preserves exact whitespace and comments when full 5-tuple
TokenInfoobjects are passed.
REPL Inspect
from tokenize import untokenize
help(untokenize)
Linked from
Related notes
- tuts/python3/stdlib_module/tokenize/tokenize Linked here; links to this page; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/detect_encoding Linked here; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/generate_tokens Linked here; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/open Linked here; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize/TokenError Linked here; shared tags: #stdlib, #tokenize
- tuts/python3/stdlib_module/tokenize links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/tokenize/TokenInfo 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