Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
contextlib.closing Class Reference
Inheritance diagram for contextlib.closing:
Inheritance graph
[legend]
Collaboration diagram for contextlib.closing:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def __enter__
def __exit__

Public Attributes

 thing
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

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()

Definition at line 119 of file contextlib.py.


Constructor & Destructor Documentation

def contextlib.closing.__init__ (   self,
  thing 
)

Definition at line 136 of file contextlib.py.

00136 
00137     def __init__(self, thing):
        self.thing = thing

Here is the caller graph for this function:


Member Function Documentation

Definition at line 138 of file contextlib.py.

00138 
00139     def __enter__(self):
        return self.thing
def contextlib.closing.__exit__ (   self,
  exc_info 
)

Definition at line 140 of file contextlib.py.

00140 
00141     def __exit__(self, *exc_info):
00142         self.thing.close()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 137 of file contextlib.py.


The documentation for this class was generated from the following file: