contextlib
index
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py
Module Docs

Utilities for with-statement contexts.  See PEP 343.

 
Modules
       
sys

 
Classes
       
__builtin__.object
closing

 
class closing(__builtin__.object)
    Context to automatically close something at the end of a block.
 
Code like this:
 
    with closing(<module>.open(<arguments>)) as f:
        <block>
 
is equivalent to this:
 
    f = <module>.open(<arguments>)
    try:
        <block>
    finally:
        f.close()
 
  Methods defined here:
__enter__(self)
__exit__(self, *exc_info)
__init__(self, thing)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
Functions
       
contextmanager(func)
@contextmanager decorator.
 
Typical usage:
 
    @contextmanager
    def some_generator(<arguments>):
        <setup>
        try:
            yield <value>
        finally:
            <cleanup>
 
This makes this:
 
    with some_generator(<arguments>) as <variable>:
        <body>
 
equivalent to this:
 
    <setup>
    try:
        <variable> = <value>
        <body>
    finally:
        <cleanup>
nested(*args, **kwds)
Combine multiple context managers into a single nested context manager.
 
This function has been deprecated in favour of the multiple manager form
of the with statement.
 
The one advantage of this function over the multiple manager form of the
with statement is that argument unpacking allows it to be
used with a variable number of context managers as follows:
 
   with nested(*managers):
       do_something()

 
Data
        __all__ = ['contextmanager', 'nested', 'closing']