[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: what's this instance?

Robert Kern

1/22/2008 8:10:00 AM

J. Peng wrote:
> def safe_float(object):
> try:
> retval = float(object)
> except (ValueError, TypeError), oops:
> retval = str(oops)
> return retval
>
> x=safe_float([1,2,3,4])
> print x
>
>
> The code above works well.But what's the instance of "oops"? where is it
> coming from? I'm totally confused on it.thanks.

The line

except (ValueError, TypeError), oops:

will trap ValueError and TypeError exceptions. The actual exception object will
be assigned to the name "oops".

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco