Question about scope

Kirk Strauser kirk at daycos.com
Tue Oct 28 11:40:31 EDT 2008


At 2008-10-24T01:08:12Z, Pat <Pat at junk.net> writes:

> ---> myGlobals.py file:
>
> class myGlobals():
>     remote_device_enabled = bool
>
> ---> my initialize.py file:
>
> from myGlobals import *
> def initialize():
>     myGlobals.remote_device_enabled = True
>
> ---> my main.py file:
>
> import from myGlobals import *
> RDE =  myGlobals.remote_device_enabled
>
> def main():
>     if RDE:    # this will not give me the correct value
>         process_device()

If you *really* want to organize your settings like this, may I suggest:

---> myGlobals.py file:

# This does nothing more than create a placeholder
remote_device_enabled = None

---> my initialize.py file:

import myGlobals
def initialize():
    myGlobals.remote_device_enabled = True

---> my main.py file:

import myGlobals
import initialize
initialize.initialize()

def main():
    if myGlobals.remote_device_enabled:
        process_device()


-- 
Kirk Strauser
The Day Companies



More information about the Python-list mailing list