diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-04-22 20:50:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-22 20:50:32 (GMT) |
commit | 22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c (patch) | |
tree | dbcdd3e7825a17432775597778ed77a7efb1b418 /Doc | |
parent | fc45cb4400409572f05c8b54f2c6f06cbefb1b4e (diff) | |
download | cpython-22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c.zip cpython-22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c.tar.gz cpython-22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c.tar.bz2 |
Minor modernization and readability improvement to the tokenizer example (GH-19558) (GH-19661)
(cherry picked from commit bf1a81258c0ecc8b52b9dcc53321c066b3ed4a67)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/re.rst | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst index 7c950bf..9abbd8b 100644 --- a/Doc/library/re.rst +++ b/Doc/library/re.rst @@ -1617,10 +1617,14 @@ The text categories are specified with regular expressions. The technique is to combine those into a single master regular expression and to loop over successive matches:: - import collections + from typing import NamedTuple import re - Token = collections.namedtuple('Token', ['type', 'value', 'line', 'column']) + class Token(NamedTuple): + type: str + value: str + line: int + column: int def tokenize(code): keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'} |