Advertisement
rfmonk

contextlib_api.py

Jan 16th, 2014
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.30 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. class Context(object):
  5.  
  6.     def __init__(self):
  7.         print '__init__()'
  8.  
  9.     def __enter__(self):
  10.         print '__enter__()'
  11.         return self
  12.  
  13.     def __exit__(self, exc_type, exc_val, exc_tb):
  14.         print '__exit__()'
  15.  
  16. with Context():
  17.     print 'Doing work in the context'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement