audiolab
audiolab copied to clipboard
Make Sndfile a "With Statement Context Manager"?
It would be nice to be able to use Sndfile like this:
from scikits.audiolab import Sndfile
with Sndfile("test.wav") as f:
# do something with f
print(f)
# no need to call f.close()!
Of course, contextlib.closing could be used for that, but why not support the with statement directly?
And, if I'm not mistaken, implementing this would be straightforward, just include the following within the class definition of Sndfile:
def __enter__(self):
return self
def __exit__(self, *ignored_args)
self.close()