ConfigParser and multiple option names
Alexis Roda
arv.nntp at gmail.com
Tue May 2 11:50:46 EDT 2006
Florian Lindner escribió:
> I think the best solution would be to use a seperation character:
>
> dir="/home/florian, /home/john, home/whoever"
RCS uses , in filenames
> What do you think? Any better ideas?
A bit ugly, but probably safer and simpler than adding arbitrary separators:
[section]
dir_1=/home/florian
dir_2=/home/john
dir_3=/home/whoever
a s(a|i)mple implementation to give you the idea, it has some bugs:
import ConfigParser
import re
class ConfigParserWithLists(ConfigParser.ConfigParser):
def setlist(self, section, option, value) :
for i, v in enumerate(value) :
self.set(section, '%s_%i' % (option, i + 1), v)
def getlist(self, section, option) :
res = []
m = re.compile('^' + option + '_\d+$').match
for oo in self.options(section) :
if m(oo) :
res.append(self.get(section, oo))
return res
HTH
More information about the Python-list
mailing list