Skip to content

Commit

Permalink
add __enter__ and __exit__ methods for with statements (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnadeau4 authored and doutriaux1 committed Apr 25, 2017
1 parent 4901f08 commit d41c270
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,10 @@ def __init__(self, path, mode, hostObj=None, mpiBarrier=False):
self.close()
raise

def __enter__(self):
return self;
def __exit__(self, type, value, traceback):
self.close()
# setattr writes external global attributes to the file
def __setattr__(self, name, value):
self.__dict__[name] = value # attributes kept in sync w/file
Expand Down

0 comments on commit d41c270

Please sign in to comment.