Application-global "switches"?

Nick Craig-Wood nick at
Mon Sep 7 10:29:55 CEST 2009

kj < at> 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 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 <nick at> --

More information about the Python-list mailing list