[Tutor] Newbie: "Global" vars across modules
Jeremy Oddo
joddo at apixels.net
Wed Dec 3 16:42:39 EST 2003
I'm guessing this has come up time and time again, but I can't seem to
find the information that I need.
Here's my problem: I want to create a global variable that EVERY module
can see. Why? Because I like to define a "debug_level" variable to print
out debugging information. I want to define "debug_level", then use it
throughout my main code and modules. I'm running into problems when I
call an external module that I've written. Here's the basic idea:
--begin gvars.py--
# Debug Level (0=NONE, 1=Normal, 2=Extended, 3=Verbose)
debug_level = 2
--myFunctions.py--
def ftest():
if (debug_level = 3):
print "VERBOSE DB: This is a verbose statement"
return 1
--testing.py--
from gvars import *
from myFunctions import *
print "Current debug level is:", debug_level
ftest()
So, testing.py is my main file. It imports gvars.py which contains my
global variable "debug_level". The testing.py file prints out
"debug_level" and all is good. However, when I make the call to "ftest()"
which is a function from A DIFFERENT FILE called "myFunctions.py", it
doesn't see "debug_level" (even if I add the line "global debug_level").
So how can I make a "truly global" global variable?
Thanks!
JO
More information about the Tutor
mailing list