kj <[email protected]> wrote:
> I'm looking for the "best-practice" way to define application-global
> read-only switches, settable from the command line. The best
> example I can think of of such global switch is the built-in variable
> __debug__. This variable is visible everywhere in a program, and
> broadly affects its operation.
This is what I've done in the past...
Create a Config class in a module called config.py and instantiate it
class Config:
def __init__(self):
self.debug = True
# etc
config = Config()
Then where you want to use it you can then use
from config import config
if config.debug:
# blah
This has the advantage that you can define some methods on your config
object (eg save).
I don't know whether this is best practice but it works for me!
--
Nick Craig-Wood <[email protected]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list