pythonic way of making a config module

Fredrik Lundh fredrik at
Wed Jan 18 17:08:35 CET 2006

andrew.fabbro at wrote:

> I'm working on an app that will be deployed on several different
> servers.  In each case, I'll want to change some config info (database
> name, paths, etc.)
> In perl, I would have done something like this:
>   Package Config;
>   <some exporting mechanics>
>   $dbname = "somename";
>   etc.
> And then use'd the module and referenced the vars as $Config::dbname.
> What is a pythonic equivalent?  These vars are only changed usually at
> install time.
> I could set up a class and then instantiate it, but that seems a
> waste...I guess what I'm looking for is either (a) a way to suck
> variables into a namespace keeping a prefix (without having to prefix
> all the vars with something like config_) - e.g., reference them as
> config.dbname or something - is this execfile?

how about a plain

    import config


where contains

    # configuration file
    dbname = "somename"

and is used like

    import config
    db = db_open(config.dbname)



More information about the Python-list mailing list