Style: global configuration data

Michael Hudson mwh21 at cam.ac.uk
Sun Nov 12 12:17:30 EST 2000


boud at rempt.xs4all.nl (Boudewijn Rempt) writes:

> I have been wondering for some time about the best way to offer
> configuration data and other global resources to all modules and classes
> in my application, other than creating a config object and passing that
> on with every constructor.  What's the received Pythonic wisdom on this?
> 
> I'd prefer to just have one instance of my config class, or my repository
> class or whatever, so if I were working in Java I'd create a singleton, but
> that somehow doesn't seem right for Python to me.

Having a module "config"?  Modules are handy in the way that if two
modules both go

import config

they get the same module.

If config.py you could read the config from a ~/.rc file, the
registry, star patterns, whatever.  I can think of situations where
this might not work, but it has the benfit of being simple...

Cheers,
M.

-- 
59. In English every word can be verbed. Would that it were so in
    our programming languages.
  -- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html



More information about the Python-list mailing list