[Python-Dev] 'With' context documentation draft (was Re: Terminology for PEP 343

Nick Coghlan ncoghlan at gmail.com
Sat Jul 9 03:03:09 CEST 2005

Terry Reedy wrote:
> Would this also work as a decorated generator?
> (If I have understood correctly, something like..)
> @contextmanager
> def tag(name)
>        print "<%s>" % name
>        yield None
>        print "</%s>" % name
> If so, I suggest putting in both versions to make the correspondence clear.

Hmm, good idea. I think I'll do that with 'closing' as well, since the 
resource management section could use a better example.

> To whoever invented this example: thanks.  It rang a bell with me so I 
> could see this as a generally usefully feature rather than a specialized 
> (though for some, important) 'close resource' feature.
> The particularly neat thing is that it converts the indent-dedent method of 
> showing structure to the alternative matched-fences method.   This is 
> certainly not limited to HTML generation.

By using closing(), decimal.getcontext(), and tag() as examples, it should be 
possible to show the versatility of the construct without making the 
documentation too confusing.


[1] http://www.python.org/sf/1234057

Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list