Given the following format (.properties or .ini):
propertyName1=propertyValue1 propertyName2=propertyValue2 ... propertyNameN=propertyValueN
For Java there is the Properties class that offers functionality to parse / interact with the above format.
Is there something similar in python's standard library (2.x) ?
If not, what other alternatives do I have ?
For .ini files there is the ConfigParser module that provides a format compatible with .ini files.
Anyway there's nothing available for parsing complete .properties files, when I have to do that I simply use jython (I'm talking about scripting).
I was able to get this to work with
ConfigParser, no one showed any examples on how to do this, so here is a simple python reader of a property file and example of the property file. Note that the extension is still
.properties, but I had to add a section header similar to what you see in .ini files... a bit of a bastardization, but it works.
The python file:
#!/usr/bin/python import ConfigParser config = ConfigParser.RawConfigParser() config.read('ConfigFile.properties') print config.get('DatabaseSection', 'database.dbname');
The property file:
[DatabaseSection] database.dbname=unitTest database.user=root database.password=
For more functionality, read: https://docs.python.org/2/library/configparser.html