HDFStore to work with 'with' statements · Issue #8791 · pandas-dev/pandas (original) (raw)

This should work:

with pandas.HDFStore('file.h5') as f:
    print(f)

as a more convenient form of

with contextlib.closing(pandas.HDFStore('file.h5')) as f:
     print(f)

AFAIK this is a easy as adding the following to HDFStore

def _enter_(self): pass
def _exit_(self): self.close()