ConfigParser and multiple option names
Larry Bates
larry.bates at websafe.com
Tue May 2 12:33:46 EDT 2006
Florian Lindner wrote:
> Hello,
> since ConfigParser does not seem to support multiple times the same option
> name, like:
>
> dir="/home/florian"
> dir="/home/john"
> dir="/home/whoever"
>
> (only the last one is read in)
>
> I wonder what the best way to work around this.
>
> I think the best solution would be to use a seperation character:
>
> dir="/home/florian, /home/john, home/whoever"
>
> What character would be best to work on various operating systems? (of what
> names may a path consist is the question)
>
> What do you think? Any better ideas?
>
> Thanks,
>
> Florian
I would either use (not tested):
[directories]
dir_01="/home/florian"
dir_02="/home/john"
dir_03="/home/whoever"
and in my program do:
INI=ConfigParser.ConfigParser()
INI.read(inifilepath)
section="directories"
dirs=[x for x in INI.options(section) if x.startswith('dir_')]
or more easily:
[init]
dirs=/home/florian,/home/john,home/whoever
and in program do:
section="init"
dirs=INI.get(section, 'dirs',).split(',')
Which one to use depends on how many dirs you would be supporting.
If it is a lot, I like the first version. If a few, the second
seems better.
-Larry Bates
More information about the Python-list
mailing list