[docs] Bug in re example

Eli Bendersky eliben at gmail.com
Sun May 22 05:44:34 CEST 2011


On Wed, May 11, 2011 at 20:36, Herman L. Jackson <hjackson at wne.edu> wrote:
> Hi,
>
> When running the tokenize example at the bottom of http://docs.python.org/py3k/library/re.html#match-objects
> I received the following error:
>
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>      File "<stdin>", line 23, in tokenize
>    NameError: global name 'val' is not defined
>
> The problem is that val is never assigned to before this line:
>
>    if typ == 'ID' and val in keywords:
>
> Here is a suggested rewrite of the that section:
>
>    elif typ != 'SKIP':
>        val = mo.group(typ)
>        if typ == 'ID' and val in keywords:
>            typ = val
>        yield Token(typ, val, line, mo.start()-line_start)
>
> Attached is a complete working example.
>

Herman, thank you for the report. I've opened Issue 12146 in the
Python tracker (http://bugs.python.org/issue12146) to track this.

Eli


More information about the docs mailing list