[code.view]

[top] / python / PyMOTW / contextlib / contextlib_nested.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """
     $Id$
     """
     #end_pymotw_header
     import contextlib
     
     @contextlib.contextmanager
     def make_context(name):
         print 'entering:', name
         yield name
         print 'exiting :', name
     
     with contextlib.nested(make_context('A'), make_context('B'), make_context('C')) as (A, B, C):
         print 'inside with statement:', A, B, C
     
     

[top] / python / PyMOTW / contextlib / contextlib_nested.py

contact | logmethods.com