"MRAB" <pyt...@mrabarnett.plus.com> wrote in message
news:mailman.591.1278900548.1673.python-l...@python.org...
Alf P. Steinbach /Usenet wrote:
def foo():
print( blah )
blah = "this is both an assignment and a declaration causing it to
exist"
foo()
Clearly when the exception is raised, referring to the variable, the
variable exists.
How about this:
>>> def foo():
print("Before:", locals())
x = 0
print("After:", locals())
>>> foo()
Before: {}
After: {'x': 0}
That's interesting. So in Python, you can't tell what local variables a
function has just by looking at it's code:
def foo(day):
if day=="Tuesday":
x=0
print ("Locals:",locals())
#foo("Monday")
Does foo() have 1 or 2 locals? That might explain some of the difficulties
of getting Python implementations up to speed.
--
Bartc
--
http://mail.python.org/mailman/listinfo/python-list