[Tutor] embedding lists in configuration files

Luke Paireepinart rabidpoobear at gmail.com
Thu Oct 12 22:59:08 CEST 2006

William O'Higgins Witteman wrote:
> I am looking for a way to use a plain text configuration file in a
> Python program instead of hard-coded values.  The configuration data
> currently is in the form of a couple of lists and some triple-quoted
> strings.
> I was looking at the ConfigParser module, but I cannot see how to use
> this format to represent lists or triple-quoted strings.  Are there any
> other suggestions?  Thanks.
I've never used configparser, but from what I read just now about it, it 
seems like this should work for lists:
#--- start INI file
list: element1,element2,element3,element4,element5
#end INI file

#your file
from ConfigParser import ConfigParser
config = ConfigParser()

print "The COW says:  "
#the following line should generate a list from the comma-separated values.
print config.get("category","list").split(',')

#--- end your file

I can't install ConfigParser at the moment to test this, but I hope it 
works :)
Tell me if it does.
As for triple-quoted strings...
I'm not sure about that.
a little bit of googling seems to agree that you can't have multi-line 
I don't know that for a fact, though.


More information about the Tutor mailing list