Created
June 5, 2015 21:09
-
-
Save offby1/584816dddcca1c690724 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from __future__ import absolute_import | |
| from __future__ import print_function | |
| from __future__ import unicode_literals | |
| class OneWay(object): | |
| def close(self): | |
| print("Here I am, being closed") | |
| class AnotherWay(OneWay): | |
| def __enter__(self): | |
| return self | |
| def __exit__(self, *args): | |
| self.close() | |
| return False | |
| if __name__ == "__main__": | |
| import contextlib | |
| with contextlib.closing(OneWay()) as ow: | |
| pass | |
| with AnotherWay() as aw: | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment