[Tutor] Program review

Ricardo Aráoz ricaraoz at gmail.com
Tue Jan 8 00:31:04 CET 2008

Kent Johnson wrote:
> 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):

Nice! How would you add exception reporting to this?

>> 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.


More information about the Tutor mailing list