Global var access in imported modules?

RgeeK slfdsasdssaf at spam.not
Wed Aug 27 21:49:50 EDT 2008


Fredrik Lundh wrote:
 >>    import utility.py
 > that tries to import a module named "py" from the package "utility".

oops - that was just a typo in my post - I meant of course "import utility"
 >
 > Python doesn't have "program-wide global" variables; if you need that,
 > create a support module and import that module everywhere you need to
 > access those variables:
 >
 >     # file: globalvars.py
 >     sName = ""
 >
 >     # file: myprogram.py
 >     import globalvars
 >     print globalvars.sName
 >
 > etc.
 >
 > </F>
 >

That's news - thanks, I didn't realize that there just wasn't the 
concept of program-wide globals.  The support module idea sounds like a 
path forward.

-R.




More information about the Python-list mailing list