[GRASS-SVN] r55948 - grass/trunk/lib/python/pygrass/vector

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 22 11:14:22 PDT 2013


Author: zarch
Date: 2013-04-22 11:14:21 -0700 (Mon, 22 Apr 2013)
New Revision: 55948

Modified:
   grass/trunk/lib/python/pygrass/vector/abstract.py
Log:
Add support for with statement in the Vector classes

Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py	2013-04-22 16:34:39 UTC (rev 55947)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py	2013-04-22 18:14:21 UTC (rev 55948)
@@ -90,6 +90,13 @@
         self.date_fmt = '%a %b  %d %H:%M:%S %Y'
         self.layer = layer
 
+    def __enter__(self):
+        self.open('r')
+        return self
+
+    def __exit__(self, exc_type, exc_value, traceback):
+        self.close()
+
     def _get_name(self):
         """Private method to obtain the Vector name"""
         if self.exist() and self.is_open():



More information about the grass-commit mailing list