Accessing variables in __main__ from modules....

Carel Fellinger cfelling at
Fri Mar 30 01:02:21 CEST 2001

nanotech at wrote:

> DEBUG would be searched for at the module scope. But I want it to 
> look for DEBUG back in __main__, like:

The most straightforwarth way to achieve this would be to import Debug
from main, or better to have a seperate options module and import from
there. like:

module options:

   DEBUG = 0

main module:

   import options
   options.DEBUG = 1

other module:

   from options import DEBUG

   if DEBUG:
     print "-I-: Reading '%s'....has %s lines...."%len(filename,lines)

groetjes, carel

More information about the Python-list mailing list