problem with variable scoping
Hrvoje Niksic
hniksic at srce.hr
Thu May 27 02:38:08 EDT 1999
Moshe Zadka <moshez at math.huji.ac.il> writes:
> Ummmm.....Tim, I beg to differ: it is more like the C++
[...]
> The Python code shadows last_line_empty only *after* the "decleration"
Not quite. Try this:
>>> a = 3
>>> def x():
... print a
... a = 10
... print a
...
What do you expect calling x() will do? I'd "normally" expect it to
print 3, then 10. What really happens is this:
>>> x()
Traceback (innermost last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in x
NameError: a
More information about the Python-list
mailing list