help with NameError
Gerrit Holl
gerrit at nl.linux.org
Tue May 27 11:26:53 EDT 2003
Shadri Shah schreef op dinsdag 27 mei om 17:13:16 +0000:
> 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))
> return 'p'
You are declaring k global, but k isn't global.
Removing the global statement helps. If you are using
Python 2.1.0b1 or higher, you can add the following statement
at the start of your source file:
from __future__ import nested_scopes
If you are using Python 2.2.0a1 or higher, you don't need
to add that statement.
If you are using Python < 2.1, I don't know what you can do
to fix your problem.
yours,
Gerrit.
--
130. If a man violate the wife (betrothed or child-wife) of another
man, who has never known a man, and still lives in her father's house, and
sleep with her and be surprised, this man shall be put to death, but the
wife is blameless.
-- Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
More information about the Python-list
mailing list