(original) (raw)
On 9 September 2010 14:32, M.-A. Lemburg <mal@egenix.com> wrote:
If my understanding is correct (which is perhaps unlikely...), using a single line will close a if opening b fails. Whereas doing them separately before the with statement risks leaving the first un-exited if creating the second fails.
Michael
�
Why do you need to put everything on one line ?\[snip...\]
afh = open(args.actual, encoding="utf-8")
efh = open(args.expected, encoding="utf-8")
with afh, efh:
� ...
In the context of files, the only purpose of the with statement
is to close them when leaving the block.
\>>> a = open('/etc/passwd')
\>>> b = open('/etc/group')
If my understanding is correct (which is perhaps unlikely...), using a single line will close a if opening b fails. Whereas doing them separately before the with statement risks leaving the first un-exited if creating the second fails.
Michael
�
\>>> with a,b: print a.readline(), b.readline()
...
at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash
at:!:25:
\>>> a
\>>> b
\--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source �(#1, Sep 09 2010)
\>>> Python/Zope Consulting and Support ... � � � �http://www.egenix.com/
\>>> mxODBC.Zope.Database.Adapter ... � � � � � � http://zope.egenix.com/
\>>> mxODBC, mxDateTime, mxTextTools ... � � � �http://python.egenix.com/
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
2010-08-19: Released mxODBC 3.1.0 � � � � � � �http://python.egenix.com/
2010-09-15: DZUG Tagung, Dresden, Germany � � � � � � � � � 6 days to go
::: Try our new mxODBC.Connect Python Database Interface for free ! ::::
� eGenix.com Software, Skills and Services GmbH �Pastor-Loeh-Str.48
� �D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
� � � � � Registered at Amtsgericht Duesseldorf: HRB 46611
� � � � � � � http://www.egenix.com/company/contact/
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas
--
http://www.voidspace.org.uk