J
Jens Thiede
In the following terminal; could someone inform me as to why it is
posible to print a global variable without having to declare it using
global. This has affected some source of mine, and allows you to
modify a global in a local scope *without* the global keyword, for
instance, you can append to a global list, but *not* assign it a new
value, for then, you create a new local variable. -- Why.
Python 2.3.2 (#1, Jan 3 2004, 23:02:08)
[GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r3, propolice)] on linux2
IDLE 1.0 x += 1;
Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
test();
File "<pyshell#4>", line 2, in test
x += 1;
UnboundLocalError: local variable 'x' referenced before assignment print x;
10
Any help would be appreciated,
Jens Thiede.
posible to print a global variable without having to declare it using
global. This has affected some source of mine, and allows you to
modify a global in a local scope *without* the global keyword, for
instance, you can append to a global list, but *not* assign it a new
value, for then, you create a new local variable. -- Why.
Python 2.3.2 (#1, Jan 3 2004, 23:02:08)
[GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r3, propolice)] on linux2
IDLE 1.0 x += 1;
Traceback (most recent call last):
File "<pyshell#5>", line 1, in -toplevel-
test();
File "<pyshell#4>", line 2, in test
x += 1;
UnboundLocalError: local variable 'x' referenced before assignment print x;
10
Any help would be appreciated,
Jens Thiede.