Thanks to visit codestin.com Credit goes to github.com
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 7de6174 commit 4b09dc7Copy full SHA for 4b09dc7
1 file changed
Doc/library/tokenize.rst
@@ -278,3 +278,22 @@ The exact token type names can be displayed using the :option:`-e` option:
278
4,10-4,11: RPAR ')'
279
4,11-4,12: NEWLINE '\n'
280
5,0-5,0: ENDMARKER ''
281
+
282
+Example of tokenizing a file programmatically, reading unicode
283
+strings instead of bytes with :func:`generate_tokens`::
284
285
+ import tokenize
286
287
+ with tokenize.open('hello.py') as f:
288
+ tokens = tokenize.generate_tokens(f.readline)
289
+ for token in tokens:
290
+ print(token)
291
292
+Or reading bytes directly with :func:`.tokenize`::
293
294
295
296
+ with open('hello.py', 'rb') as f:
297
+ tokens = tokenize.tokenize(f.readline)
298
299
0 commit comments