浏览代码

Add support for with statement in the Vector classes

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55948 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli 12 年之前
父节点
当前提交
3627d49d54
共有 1 个文件被更改,包括 7 次插入0 次删除
  1. 7 0
      lib/python/pygrass/vector/abstract.py

+ 7 - 0
lib/python/pygrass/vector/abstract.py

@@ -90,6 +90,13 @@ class Info(object):
         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():