How to change globale variables? Hehlp!!
etsang at my-deja.com
etsang at my-deja.com
Thu Nov 9 15:35:25 EST 2000
Hi I tried the code, but i ahve a problem. right after the raw_input
line. It says command not found.
Can u help?
In article <8ueuss$a5a$1 at news.udel.edu>,
"Terry Reedy" <tjreedy at udel.edu> wrote:
> > 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
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list