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

Nick Coghlan ncoghlan at gmail.com
Fri Jul 8 16:21:35 CEST 2005


Phillip J. Eby wrote:
> I suggest changing this to something like this:
>> class tag(object):
> def __init__(self,name):
> self.name = name
> def __enter__(self):
> print "<%s>" % name
> def __exit__(self):
> print "</%s>" % name
>> with tag('html'):
> # ... etc.
>> So that it's obvious where the implementation is coming from. 
> Otherwise, it looks altogether too magical.

Done - included in the latest version on SF. [1]
> Also, the posted draft doesn't explain what happens to the __enter__ 
> return value, either in a literal sense or in the sense of where it fits 
> in the overall concept of context management.

I've tried to clarify this by showing usage of the closing() context manager.
Cheers,
Nick.
[1] http://www.python.org/sf/1234057
-- 
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
 http://boredomandlaziness.blogspot.com


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /