ConfigParser: writes a list but reads a string?

Fuzzyman fuzzyman at gmail.com
Mon Jan 16 04:17:25 EST 2006


ConfigObj will read and write list values.

You get all sorts of other advantages as well (nested subsections to
any depth), and the resulting code will be much simpler.

from configobj import ConfigObj
cfgfile = "cfgtest.ini"

cfg = ConfigObj(cfgfile)
t1 = range(1,11)
# no *need* to create a subsection
cfg['test'] = {}
cfg['test']['testlist'] = t1
cfg.write()

To read it back in :

from configobj import ConfigObj
cfgfile = "cfgtest.ini"

cfg = ConfigObj(cfgfile)
print cfg['test']['testlist']

http://www.voidspace.org.uk/python/configobj.html

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml




More information about the Python-list mailing list