At 09:12 PM 7/6/2005 +1000, Nick Coghlan wrote: >Another example is the use of contexts to handle insertion of the >appropriate tags when generating HTML: > > with html: > with body: > with h1: > print "Some heading" > with p: > print "This is paragraph 1" > with p: > print "This is paragraph 2" > with h2: > print "Another heading"
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. 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. _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com