Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import contextlib
- class Door(object):
- def __init__(self):
- print ' __init__()'
- def close(self):
- print ' close()'
- print 'Normal Example:'
- with contextlib.closing(Door()) as door:
- print ' inside with statement'
- print '\nError handling example:'
- try:
- with contextlib.closing(Door()) as door:
- print ' raising from inside with statement'
- raise RuntimeError('error message')
- except Exception, err:
- print ' Had an error:', err
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement