Scope of variable inside list comprehensions?
Jean-Michel Pichavant
jeanmichel at sequans.com
Tue Dec 6 05:38:07 EST 2011
Steven D'Aprano wrote:
> On Mon, 05 Dec 2011 19:57:15 +0100, Jean-Michel Pichavant wrote:
>
>
>> The proper way to propagate information with exceptions is using the
>> exception itself:
>>
>> try:
>> songs = [Song(_id) for _id in song_ids]
>> except Song.DoesNotExist, exc:
>> print exc
>>
>
>
> I'm not entirely sure that this is the proper way to propagate the
> exception. I see far to many people catching exceptions to print them, or
> worse, to print a generic, useless message like "an error occurred".
>
[snip]
You misread me, I was referering to passing *information* with exception
(in other words, use the exception attributes). In the example I gave,
the exception has the songId value responsible for raising the error.
I totaly second your opinion on how poor the above handler is (hmm not
sure about this grammar construct, it sounds like a Yoda sentence).
JM
More information about the Python-list
mailing list