ConfigParser
Larry Bates
lbates at syscononline.com
Thu Mar 17 08:21:01 EST 2005
Sergey wrote:
> Is there an alternative to standard module ConfigParser, which can use
> delimitier symbol other than ":" and "=", preferaby just space?
> I need to parse such configs:
>
> [Passwords]
> 2:5020/758 xxxx
> 2:5020/794 yyyy
>
> ConfigParser is not able to work with option names which contain symbol ':'
> It is not difficult to modify ConfigParser to resolve it, but may be another
> solution already exists?
>
>
What you need is an option keyname in front of each password entry in
the [Passwords] section: I do this quite a lot:
[Passwords]
password_001=2:5020/758 xxxx
password_002=2:5020/794 yyyy
.
.
.
You can then get a list of passwords from .INI like this:
INI=ConfigParser.ConfigParser()
INI.read(inifilename)
section="Passwords"
passwordentries=[p for p in INI.options(section) if p.startswith('password_')]
passwordentries.sort() # If you want to process them in order
or to get list of passwords
passwordlist=[INI.get(section, pk) for pk in passwordentries]
Larry Bates
More information about the Python-list
mailing list