Import config into global space?

simo simoninusa2001 at yahoo.co.uk
Tue Mar 30 22:54:41 EST 2004


I'm writing a module, and it's getting too big to cope with as it has
a lot of configuration in it - constants, dictionaries etc; it'd be
nice to externalise this and keep my module down to just classes/defs
etc.

What I'd like to do is have myprog.py import config.py and be able to
reference the configuration variables globally - i.e. I could just
reference myvar instead of config.myvar

So I'd have something like this:

config.py
=========

ID_TOOLBAR = 105

myprog.py
=========

import config
print ID_TOOLBAR

result
======

>> 105

It doesn't seem to work though, as global is limited to modules as far
as I know.

Any ideas how to do this, it's basically like a require or #include in
Perl/C...



More information about the Python-list mailing list