Question about scope
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Fri Oct 24 04:08:48 EDT 2008
More information about the Python-list mailing list
Fri Oct 24 04:08:48 EDT 2008
- Previous message (by thread): Question about scope
- Next message (by thread): Question about scope
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Pat a écrit : (snip) > > Stripping out the extra variables and definitions, this is all that > there is. > Whether or not this technique is *correct* programming is irrelevant. It's obviously relevant. If it was correct, it would work, and you wouldn't be asking here !-) > I > simply want to know why scoping doesn't work like I thought it would. > > > ---> myGlobals.py file: > > class myGlobals(): > remote_device_enabled = bool <irrelevant> You're using the class as a bare namespace. FWIW, you could as well use the module itself - same effect, simplest code. </irrelevant> > ---> my initialize.py file: > > from myGlobals import * > def initialize(): > myGlobals.remote_device_enabled = True > > ---> my main.py file: > > import from myGlobals import * I assume the first "import" is a typo. But this sure means you didn't run that code. > RDE = myGlobals.remote_device_enabled > > def main(): > if RDE: # this will not give me the correct value For which definition of "correct value" ? You didn't import nor execute initialize() so far, so at this stage RDE is bound to the bool type object. FWIW, note that calling initialize *after* the assignement to RDE won't change the fact that RDE will be still bound to the the bool type object. <irrelevant> You may want to have a look at how other Python application manage application-wide settings. </irrelevant>
- Previous message (by thread): Question about scope
- Next message (by thread): Question about scope
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list