On this page
  1. tokenize.untokenize
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from tokenize import untokenize
help(untokenize)

Linked from

Related notes