ConfigParser

S

Sergey

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?
 
L

Larry Bates

Sergey said:
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
 
S

Serge Orlov

Sergey said:
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?

In case you won't get a satisfying answer there is always python
package index: http://www.python.org/pypi Go to search and enter
"config" into the keyword field, you'll get seven results, looking at
description five of them are configuration file parsers.

Serge.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,222
Messages
2,571,142
Members
47,757
Latest member
PDIJaclyn

Latest Threads

Top