We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 548685e commit 6dbd843Copy full SHA for 6dbd843
Doc/library/tokenize.rst
@@ -267,3 +267,22 @@ The exact token type names can be displayed using the :option:`-e` option:
267
4,10-4,11: RPAR ')'
268
4,11-4,12: NEWLINE '\n'
269
5,0-5,0: ENDMARKER ''
270
+
271
+Example of tokenizing a file programmatically, reading unicode
272
+strings instead of bytes with :func:`generate_tokens`::
273
274
+ import tokenize
275
276
+ with tokenize.open('hello.py') as f:
277
+ tokens = tokenize.generate_tokens(f.readline)
278
+ for token in tokens:
279
+ print(token)
280
281
+Or reading bytes directly with :func:`.tokenize`::
282
283
284
285
+ with open('hello.py', 'rb') as f:
286
+ tokens = tokenize.tokenize(f.readline)
287
288
0 commit comments