]> granicus.if.org Git - python/commitdiff
Fix an error in the last contextlib.closing example
authorNick Coghlan <ncoghlan@gmail.com>
Wed, 26 Apr 2006 11:50:04 +0000 (11:50 +0000)
committerNick Coghlan <ncoghlan@gmail.com>
Wed, 26 Apr 2006 11:50:04 +0000 (11:50 +0000)
Doc/lib/libcontextlib.tex

index 7f07b376e00be1b7046f513a7c92ea9fd611656b..9ff85249d911f2e58ea835fcfa401e62490e3362 100644 (file)
@@ -149,8 +149,7 @@ occurs, \code{page.close()} will be called when the \keyword{with}
 block is exited.
 
 Context managers with a close method can use this context factory
-directly without needing to implement their own
-\method{__context__()} method.
+to easily implement their own \method{__context__()} method.
 \begin{verbatim}
 from __future__ import with_statement
 from contextlib import closing
@@ -158,7 +157,8 @@ from contextlib import closing
 class MyClass:
     def close(self):
         print "Closing", self
-    __context__ = closing
+    def __context__(self):
+        return closing(self)
 
 >>> with MyClass() as x:
 ...     print "Hello from", x