I want to separate the debug outputs from production ones by defining a variable that can be used throughput the module. It cannot be defined in environment. Any suggestions for globals reused across classes in modules? Additionally is there a way to configure this variable flag for telling appengine that dont use this code.
Have a look at the logging module, which is fully supported by Google App Engine. You can specify logging levels such as debug, warning, error, etc. They will show up in the dev server console, and will also be stored in the request log.
If you're after executing specific code only when running the dev server, you can do this:
if os.environ['SERVER_SOFTWARE'].startswith('Development'):
print 'Hello world!'
The SERVER_SOFTWARE variable is always set by Google App Engine.
As for module specific variables; modules are objects and can have values just as any other object:
my_module.debug = True
All module-level variables are global to all classes in the module.
Here's my file: mymodule.py
import this
import that
DEBUG = True
class Foo( object ):
def __init__( self ):
if DEBUG: print self.__class__, "__init__"
# etc.
class Bar( object ):
def do_work( self ):
if DEBUG: print self.__class__, "do_work"
# etc.
A single, module-level DEBUG
variable will be found by all instances of these two classes. Other modules (e.g,. this.py
and that.py
) can have their own DEBUG
variables. These would be this.DEBUG
or that.DEBUG
, and are unrelated.