How to change globale variables? Hehlp!!
Terry Reedy
tjreedy at udel.edu
Thu Nov 9 14:50:43 EST 2000
> Is there a way that file B can chnage the global variable in file A and
> reflect these chnage simulatanouesly to all three files??
>
> Can python do that??
Easily: Access as attribute of module. Example:
# a.py
filename=None #not known until runtime
def filefuncA():
fA = open(filename) # does something with filename once set
# b.py
import a
a.filename = raw_input('Enter a filename: ")
a.filefunc() # will now work
#c.py
import a
print a.filename
a.filefunc() # a.filename better have legitimate value
Terry J. Reedy
More information about the Python-list
mailing list