import and global trouble
dag4004
dgeranton at alpha3i.com
Fri Oct 10 06:19:42 EDT 2003
Hello,
I have a strange behavior with global and module.
Here is the module named: foo.py
bar = "egg"
def f1():
global bar
print bar
bar = "bob"
print bar
When i use it :
>>> from foo import *
>>> bar # Value of bar in main prog
'egg'
>>> f1() # Try to change bar value through foo module
'egg'
'bob' # It seems to work
>>> bar # I check if it job is done
'egg' # Damned ! The value is not changing
>>> f1() # And in module area ?
'bob' # All seems good, grrr !
'bob'
>>>
I do not understand.
Is bar a global name?
With which dico do i work?
Is there some thing special to know when we use from --- import *
Is there some one an explanation?
Thanks.
Good hack.
Damien GERANTON
More information about the Python-list
mailing list