help with NameError
Steven Taschuk
staschuk at telusplanet.net
Tue May 27 12:05:34 EDT 2003
Quoth Shadri Shah:
> I request help in understanding why I'm getting NameError
> here in the code below:
>
> import re
>
> def t(s):
> k = []
>
> def g(j):
> global k
> k.append(j.group(0))
There's no global variable k. (k is not in the top-level module
scope, it's in t's scope. With sufficiently recent Python you
have nested scopes, which means that here you can just refer to k.
No global statement needed or desired.)
--
Steven Taschuk staschuk at telusplanet.net
Every public frenzy produces legislation purporting to address it.
(Kinsley's Law)
More information about the Python-list
mailing list