back to public projects
xmlsettings.py
version: | 1.0.0-beta |
author: | Alejandro López Correa |
contact: | ten.akips@cla |
license: | MIT License |
A python module to enable easy access to configuration files and other light xml files.
Tested with python 2.7 and 3.2
Quick example:
import xmlsettings
import datetime
config = xmlsettings.XMLSettings( 'config.xml' )
userName = config.get( 'user_data/user_name', 'jdoe' )
userLanguage = config.get( 'user_data/language', 'en' )
userLevel = config.get( 'user_data/level', 100 )
# userLevel is of type int
userCredits = config.get( 'user_data/credits', 0.0 )
# userCredits is of type float
config.put( 'user_data/user_name', userName )
config.put( 'user_data/level', userLevel+1 )
config.put( 'timeStamp', str(datetime.datetime.now()) )
config.save()
Object initialization, providing a file path. In case the file does no exist, path is stored for later use in save().
Returns the value of an attribute in a given path, or defaultValue in case it does not exist. If the value is found in the file, the type of defaultValue is used to cast it. For example, if defaultValue is an integer, the internal value (a string) is returned as int(value).
Supported value types are: str, unicode, int, float, bool.
Returns the value of an attribute in a given path, or defaultValue in case it does not exist. If the value is found in the file, the type of defaultValue is used to cast it, as in get() method.
Sets the value of a given path.
Sets an attribute in path to the given value.
Saves the current data in case there has been any changes. This method accepts an optional argument 'fpath' to specify a file path.
For now, the only option available is direct download of source code (single file).
xmlsettings.py
- Add support for sequences.
- Improve support for non-text values.