Skip to content

Instantly share code, notes, and snippets.

@durden
Created May 16, 2013 19:49
Show Gist options
  • Save durden/5594527 to your computer and use it in GitHub Desktop.
Save durden/5594527 to your computer and use it in GitHub Desktop.
Context managers are smart..er than you think...
class mycontext(object):
def __enter__(self, *args, **kwargs):
print 'enter'
def __exit__(self, *args, **kwargs):
print 'exit'
def myfunc():
with mycontext():
# Gee what will happen here?
return 'Returning'
def main():
print myfunc()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment