Thread Previous • Date Previous • Date Next • Thread Next |
Barry Warsaw wrote:
it doesn't scale well for more than resource;'one'?------------------------------^
Indeed.
>>> with open('/etc/passwd') as a, open('/etc/group') as b: ... pass
That's very good news! And this presumably takes care of the "what if the second open() fails" and "what if b's cleanup depends on a being there" corner-case stuff. At this point it's not longer the thin layer of sugar I had listed as an irrelevant gripe.
I'm not sure the with-statement was designed for transactions, but one good reason why it shouldn't be used for transactions is because (IME) proper handling doesn't fit into pure try/finally:
We're in full agreement there. The reason I seized on this is that I saw transaction handling documented on the python site as the main justifying use-case for the exception-handling design.
So I still say: by all means use it, but let's stay away from exception-dependent and exception-eating exit handlers for as long as we can!
Jeroen
Thread Previous • Date Previous • Date Next • Thread Next |