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. Cheers, Nick. [1] http://www.python.org/sf/1234057 -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia --------------------------------------------------------------- http://boredomandlaziness.blogspot.com
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4