[Python-3000] self-contained exceptions

Ka-Ping Yee python at zesty.ca
Thu Jan 4 08:41:49 CET 2007


On 1/3/07, Phillip J. Eby <pje at telecommunity.com> wrote:
>Or perhaps translate blocks of the form:
>> except ExcType, e:
> # body
>>to:
>> except ExcType, e:
> try:
> # body
> finally:
> del e

That's much nicer! (I feel silly now for not realizing there was
no need for the weakref...)
> Actually, on second thought it occurs to me that the above code isn't a
> 100% correct translation, because if "body" contains its own "del e", then
> it will fail. So a pure translation strategy isn't really practical,
> unfortunately. We'd have to generate something like:
>> if 'e' in locals():
> del e

How about this?
 except ExcType, e:
 try:
 # body
 finally:
 e = None
-- ?!ng


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /