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 -- http://mail.python.org/mailman/listinfo/python-list