Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libcontextlib.tex @ 39042:c02fa187e0f4 legacy-trunk
Part of SF patch #1484695. This removes dead code. The chksum was
already verified in .frombuf() on the lines above. If there was
a problem an exception is raised, so there was no way this condition
could have been true.
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 10 Jul 2006 00:23:17 +0000 |
| parents | e92a8b8eec73 |
| children | 6d246ac63198 |
| rev | line source |
|---|---|
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
1 \section{\module{contextlib} --- |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
2 Utilities for \keyword{with}-statement contexts.} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
3 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
4 \declaremodule{standard}{contextlib} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
5 \modulesynopsis{Utilities for \keyword{with}-statement contexts.} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
6 |
|
37260
e12e493b5244
Add version added info for with statement and context managers
Neal Norwitz <nnorwitz@gmail.com>
parents:
37258
diff
changeset
|
7 \versionadded{2.5} |
|
e12e493b5244
Add version added info for with statement and context managers
Neal Norwitz <nnorwitz@gmail.com>
parents:
37258
diff
changeset
|
8 |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
9 This module provides utilities for common tasks involving the |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
10 \keyword{with} statement. |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
11 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
12 Functions provided: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
13 |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
14 \begin{funcdesc}{contextmanager}{func} |
|
37971
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
15 This function is a decorator that can be used to define a factory |
|
38102
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
16 function for \keyword{with} statement context managers, without |
|
37971
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
17 needing to create a class or separate \method{__enter__()} and |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
18 \method{__exit__()} methods. |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
19 |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
20 A simple example (this is not recommended as a real way of |
|
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
21 generating HTML!): |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
22 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
23 \begin{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
24 from __future__ import with_statement |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
25 from contextlib import contextmanager |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
26 |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
27 @contextmanager |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
28 def tag(name): |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
29 print "<%s>" % name |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
30 yield |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
31 print "</%s>" % name |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
32 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
33 >>> with tag("h1"): |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
34 ... print "foo" |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
35 ... |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
36 <h1> |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
37 foo |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
38 </h1> |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
39 \end{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
40 |
|
37971
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
41 The function being decorated must return a generator-iterator when |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
42 called. This iterator must yield exactly one value, which will be |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
43 bound to the targets in the \keyword{with} statement's \keyword{as} |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
44 clause, if any. |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
45 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
46 At the point where the generator yields, the block nested in the |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
47 \keyword{with} statement is executed. The generator is then resumed |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
48 after the block is exited. If an unhandled exception occurs in the |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
49 block, it is reraised inside the generator at the point where the yield |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
50 occurred. Thus, you can use a |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
51 \keyword{try}...\keyword{except}...\keyword{finally} statement to trap |
|
37953
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
52 the error (if any), or ensure that some cleanup takes place. If an |
|
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
53 exception is trapped merely in order to log it or to perform some |
|
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
54 action (rather than to suppress it entirely), the generator must |
|
38102
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
55 reraise that exception. Otherwise the generator context manager will |
|
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
56 indicate to the \keyword{with} statement that the exception has been |
|
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
57 handled, and execution will resume with the statement immediately |
|
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
58 following the \keyword{with} statement. |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
59 \end{funcdesc} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
60 |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
61 \begin{funcdesc}{nested}{mgr1\optional{, mgr2\optional{, ...}}} |
|
37971
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
62 Combine multiple context managers into a single nested context manager. |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
63 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
64 Code like this: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
65 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
66 \begin{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
67 from contextlib import nested |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
68 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
69 with nested(A, B, C) as (X, Y, Z): |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
70 do_something() |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
71 \end{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
72 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
73 is equivalent to this: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
74 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
75 \begin{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
76 with A as X: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
77 with B as Y: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
78 with C as Z: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
79 do_something() |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
80 \end{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
81 |
|
37953
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
82 Note that if the \method{__exit__()} method of one of the nested |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
83 context managers indicates an exception should be suppressed, no |
|
37953
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
84 exception information will be passed to any remaining outer context |
|
38102
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
85 managers. Similarly, if the \method{__exit__()} method of one of the |
|
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
86 nested managers raises an exception, any previous exception state will |
|
e92a8b8eec73
Get rid of a couple more context object references, fix some markup and clarify what happens when a generator context function swallows an exception.
Nick Coghlan <ncoghlan@gmail.com>
parents:
38101
diff
changeset
|
87 be lost; the new exception will be passed to the |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
88 \method{__exit__()} methods of any remaining outer context managers. |
|
37953
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
89 In general, \method{__exit__()} methods should avoid raising |
|
d60fbc54c0d4
Change PEP 343 related documentation to use the term context specifier instead of context object
Nick Coghlan <ncoghlan@gmail.com>
parents:
37937
diff
changeset
|
90 exceptions, and in particular they should not re-raise a |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
91 passed-in exception. |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
92 \end{funcdesc} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
93 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
94 \label{context-closing} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
95 \begin{funcdesc}{closing}{thing} |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
96 Return a context manager that closes \var{thing} upon completion of |
|
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
97 the block. This is basically equivalent to: |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
98 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
99 \begin{verbatim} |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
100 from contextlib import contextmanager |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
101 |
|
38101
6bc1e83a97a6
Finish bringing SVN into line with latest version of PEP 343 by getting rid of all remaining references to context objects that I could find. Without a __context__() method context objects no longer exist. Also get test_with working again, and adopt a suggestion from Neal for decimal.Context.get_manager()
Nick Coghlan <ncoghlan@gmail.com>
parents:
38084
diff
changeset
|
102 @contextmanager |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
103 def closing(thing): |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
104 try: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
105 yield thing |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
106 finally: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
107 thing.close() |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
108 \end{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
109 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
110 And lets you write code like this: |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
111 \begin{verbatim} |
|
37258
7b52480c12c6
Fix some missing imports
Phillip J. Eby <pje@telecommunity.com>
parents:
37256
diff
changeset
|
112 from __future__ import with_statement |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
113 from contextlib import closing |
|
37258
7b52480c12c6
Fix some missing imports
Phillip J. Eby <pje@telecommunity.com>
parents:
37256
diff
changeset
|
114 import codecs |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
115 |
|
37971
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
116 with closing(urllib.urlopen('http://www.python.org')) as page: |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
117 for line in page: |
|
37937
977e7a7e155a
Update contextlib documentation to use the same terminology as the module implementation
Nick Coghlan <ncoghlan@gmail.com>
parents:
37260
diff
changeset
|
118 print line |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
119 \end{verbatim} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
120 |
|
37971
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
121 without needing to explicitly close \code{page}. Even if an error |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
122 occurs, \code{page.close()} will be called when the \keyword{with} |
|
af44db2a9523
Move the PEP 343 documentation and implementation closer to the
Nick Coghlan <ncoghlan@gmail.com>
parents:
37953
diff
changeset
|
123 block is exited. |
|
37256
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
124 \end{funcdesc} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
125 |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
126 \begin{seealso} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
127 \seepep{0343}{The "with" statement} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
128 {The specification, background, and examples for the |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
129 Python \keyword{with} statement.} |
|
94f1613b87d5
Document the contextlib module.
Phillip J. Eby <pje@telecommunity.com>
parents:
diff
changeset
|
130 \end{seealso} |
