[Tutor] How do you implement a config file?

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Sun Jul 16 07:44:43 CEST 2006



> I am writing a small python application that needs a few variables to be 
> end user configurable. Right now I just have the variables right up 
> front where the user can tweak them in the program code and a big 
> commented line that says "Nothing editable past this point." But I would 
> like to be able to break this out into a separate config file. There are 
> two ways I see to do this:

Hi Tracy,

[config parser approach cut]

> I don't see any good way to do that either without actually making my 
> config file a module and calling it config.py instead of 
> application.config.

This second approach --- using a module as a configuration file --- is the 
programmer-friendly one.  *grin* If you can get away with this, it's 
probably the simplest to implement.  It also seems to be the approach that 
most Python programs use, bar more sophisticated approaches like XML or 
some other structured data format.

We had some discussion about this earlier the last few weeks (and months! 
Someone should put this on the FAQ!), and the concensus seems to be that 
ConfigParser is a bit limiting:

     http://aspn.activestate.com/ASPN/Mail/Message/python-Tutor/3116794
     http://mail.python.org/pipermail/tutor/2006-June/047557.html

Best of wishes!


More information about the Tutor mailing list