Initializing defaults to module variables

Burton Samograd kruhftREMOVE at gmail.com
Wed Apr 12 13:13:35 EDT 2006


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
I don't have to scatter default values all over my code in try/catch
blocks)? Basically, I would like to be able to do something like this:

        config.login = "noone"
        config.password = "secret"
        .
        .
        .
        import sys
        from posix import environ
        sys.path.append(environ["HOME"]+"/.program")
        import config

So I guess the real question is:

        Is there a way to create a module namespace and populate it
        before sourcing the file?

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



More information about the Python-list mailing list