Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- class WithinContext(object):
- def __init__(self, context):
- print 'WithinContext.__init__(%s)' % context
- def do_something(self):
- print 'WithinContext.do_something()'
- def __del__(self):
- print 'Withincontext.__del__'
- class Context(object):
- def __init__(self):
- print 'Context.__init()'
- def __enter__(self):
- print 'Context.__enter__()'
- return WithinContext(self)
- def __exit__(self, exc_type, exc_val, exc_tb):
- print 'Context.__exit__()'
- with Context() as c:
- c.do_something()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement