[Tutor] Configuration File Pattern

Chad Crabtree flaxeater at gmail.com
Mon Jul 21 18:14:42 CEST 2008


What I use in this situation is the INI config file parser in the
standard lib.  It's easy to use

##CONFIG FILE####
[paths]
images=/home/user/Images


##CODE###
import ConfigParser
config=ConfigParser.ConfigParser()
config.readfp(open(conf,'r'))
print config


http://docs.python.org/lib/module-ConfigParser.html

On Mon, Jul 21, 2008 at 10:08 AM, Daniele <d.conca at gmail.com> wrote:
> Hi list,
> I've recently developed a basic python program which needs to store
> some data in a file (e.g. a directory path).
> What the program needs is a dictionary containing the data, so I used
> the pickle module to store the dictionary in a file and read it back
> when the program is launched.
> I wanted to know which is the common pattern in python programming in
> this case, because the way I've choosen only lets the user configure
> the data via a GUI (the file is somehow "compiled"). Is it better to
> store the data in a text file and then parse it and construct a
> dictionary? Or is there e third way?
>
> Thanks, Daniele
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list