Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Sndfile a "With Statement Context Manager"? #17

Open
mgeier opened this issue Jul 13, 2013 · 0 comments
Open

Make Sndfile a "With Statement Context Manager"? #17

mgeier opened this issue Jul 13, 2013 · 0 comments

Comments

@mgeier
Copy link

mgeier commented Jul 13, 2013

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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant