[Tutor] Program review
Kent Johnson
kent37 at tds.net
Mon Jan 7 12:45:07 CET 2008
Jeff Younker wrote:
> Or if you're using python 2.5 then you can use with statements:
>
> from __future__ import with_statements
> from contextlib import closing
> ...
> def mails(self):
> with closing(open_file(self.direcciones)) as fIncl:
> with closing(open_file(self.excluidas)) as fExcl:
closing() is not needed, this can be written as
with open_file(self.direcciones) as fIncl:
with open_file(self.excluidas) as fExcl:
because open files are context managers.
Or,
from contextlib import nested
with nested(open_file(self.direcciones), open_file(self.excluidas))
as (fIncl, fExcl):
> As you have it written it terminates, but it also silently consumes the
> exception. If something goes wrong with your program then there is
> no way of diagnosing the problem because the failure cause is never
> reported.
The exception is written to the log. He may not want the traceback
printed to the console.
Kent
More information about the Tutor
mailing list