"hollowspook" <[EMAIL PROTECTED]> wrote: > from test import * > b=1 > aa() > > The error message is : > Traceback (most recent call last): > File "<interactive input>", line 1, in ? > File "test.py", line 3, in aa > b=b+1 > NameError: global name 'b' is not defined > > Why this happens? Please do me a favor.
The global statement makes a name global to a module, it doesn't make it global to the entire program. The function aa is in module test, the statements you entered in the shell are in a different module called __main__. The particular form of import you used may also be confusing you: just because you imported '*' doesn't change the function: 'aa' was defined in the module 'test' and that is where it still looks for its global variables, all the import did was define a new name 'aa' in the __main__ module which refers to the same function object as 'aa' in 'test'. -- http://mail.python.org/mailman/listinfo/python-list