Initializing defaults to module variables

Burton Samograd kruhftREMOVE at gmail.com
Thu Apr 13 12:27:43 EDT 2006


"Fredrik Lundh" <fredrik at pythonware.com> writes:
> since you know the name of the config file you're looking for, you can
> simplify (and unweirdify) your code a bit by changing your config file to
> look like this:
> 
>     # File: config.py
> 
>     #
>     # configuration defaults
> 
>     some_param = "value"
>     some_other_param = 1
> 
>     #
>     # get user overrides
> 
>     import os
>     try:
>         execfile(os.path.expanduser("~/.program/config.py"))
>     except IOError:
>         pass # ignore missing config file, but not syntax errors
> 
>     # end of file
> 
> with this in place, you just have to do
> 
>     import config
> 
> in any application module than needs to access the configuration
> data.

nice, that looks to be just what I was looking for.  thanks.

-- 
burton samograd					kruhft .at. gmail
kruhft.blogspot.com	www.myspace.com/kruhft	metashell.blogspot.com



More information about the Python-list mailing list