pythonic way of making a config module
Fredrik Lundh
fredrik at pythonware.com
Wed Jan 18 11:08:35 EST 2006
andrew.fabbro at gmail.com 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 config.py contains
# configuration file
dbname = "somename"
and is used like
import config
db = db_open(config.dbname)
etc.
</F>
More information about the Python-list
mailing list