Initializing defaults to module variables
Kent Johnson
kent at kentsjohnson.com
Wed Apr 12 13:52:51 EDT 2006
Burton Samograd wrote:
> Hi,
>
> I'm writing an app that stores some user configuration variables in a
> file ~/.program/config, which it then imports like so:
>
> import sys
> from posix import environ
> sys.path.append(environ["HOME"]+"/.program")
> import config
>
> I can then access the configuration through code like:
>
> login(config.username)
>
> My question is, how can I setup my program defaults so that they can
> be overwritten by the configuration variables in the user file (and so
You could use the ConfigParser module instead of putting your config in
a Python module. ConfigParser allows specifying defaults.
Kent
More information about the Python-list
mailing list