Skip to content

Instantly share code, notes, and snippets.

@offby1
Created June 5, 2015 21:09
Show Gist options
  • Select an option

  • Save offby1/584816dddcca1c690724 to your computer and use it in GitHub Desktop.

Select an option

Save offby1/584816dddcca1c690724 to your computer and use it in GitHub Desktop.
#!/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