ConfigParser and options

george young gry at ll.mit.edu
Thu Feb 13 10:30:57 EST 2003


cepl at surfbest.net (Matej Cepl) wrote in message news:<35993bcb.0302121540.f8d62e2 at posting.google.com>...
> I would like to write a config file parser, but I would like to allow
> user to
> set just some options (when he wants a default values for the rest of
> them). How can I do it?
> 
> I can write something like
> 
> for rcvar in rcconfile.options(currsection):
>      ...
>      variable = get(currsection,rcvar)
> 
> but how do I connect variable to the real variable which is equal to
> the name of the option in the file? Other option is to go in one huge
> if ... construct
> 
> if rcconfile.has_key(currsection,'variable1'):
>      variable1 = rcconfile.get(currsection,'variable1')
> if rcconfile.has_key(currsection,'variable2'):
>      variable2 = rcconfile.get(currsection,'variable2')
> if ...

Have you looked at the ConfigParser module that comes with python?
It might be a good starting place...




More information about the Python-list mailing list