[GRASS-SVN] r50980 - grass/branches/releasebranch_6_4/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Mar 3 09:54:23 EST 2012
Author: martinl
Date: 2012-03-03 06:54:22 -0800 (Sat, 03 Mar 2012)
New Revision: 50980
Modified:
grass/branches/releasebranch_6_4/lib/python/core.py
Log:
glynn: Use KeyValue object for key-value data
(allows use of e.g. region.rows as an alternative to region['rows'])
(merge r50972 from trunk)
Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py 2012-03-03 14:53:16 UTC (rev 50979)
+++ grass/branches/releasebranch_6_4/lib/python/core.py 2012-03-03 14:54:22 UTC (rev 50980)
@@ -479,6 +479,27 @@
return tmp
+class KeyValue(dict):
+ """A general-purpose key-value store.
+
+ KeyValue is a subclass of dict, but also allows entries to be read and
+ written using attribute syntax. Example:
+
+ \code
+ >>> region = grass.region()
+ >>> region['rows']
+ 477
+ >>> region.rows
+ 477
+ \endcode
+ """
+
+ def __getattr__(self, key):
+ return self[key]
+
+ def __setattr__(self, key, value):
+ self[key] = value
+
# key-value parsers
def parse_key_val(s, sep = '=', dflt = None, val_type = None, vsep = None):
@@ -493,7 +514,7 @@
@return parsed input (dictionary of keys/values)
"""
- result = {}
+ result = KeyValue()
if not s:
return result
More information about the grass-commit
mailing list