Can you change the separator from comma (,
) to a semicolon (:
) or use the equals (=
) sign? In that case ConfigParser
will automatically do it for you.
For e.g. I parsed your sample data after changing the comma to equals:
# urls.cfg
[URLs]
Google=www.google.com
Hotmail=www.hotmail.com
Yahoo=www.yahoo.com
# Scriptlet
import ConfigParser
filepath = '/home/me/urls.cfg'
config = ConfigParser.ConfigParser()
config.read(filepath)
print config.items('URLs') # Returns a list of tuples.
# [('hotmail', 'www.hotmail.com'), ('google', 'www.google.com'), ('yahoo', 'www.yahoo.com')]