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

tokenize.generate_tokens

Prev: tokenize.detect_encoding | Up: tokenize | Next: tokenize.open
Rel: tokenize.detect_encoding, tokenize.open, tokenize.TokenError, tokenize.TokenInfo
Ref: docs.python.org — tokenize.generate_tokens
Tags: #public #python3 #stdlib #tokenize


Import

import tokenize
from tokenize import generate_tokens

Signature & Overview

tokenize.generate_tokens(readline)

Tokenize a source reading Python code as unicode strings.

Usage

import io, tokenize

toks = [t.string for t in tokenize.generate_tokens(io.StringIO('a + b').readline) if t.string]
assert toks == ['a', '+', 'b']

Gotchas

REPL Inspect

from tokenize import generate_tokens
help(generate_tokens)

Linked from

Related notes