Author brett.cannon
Date 2003-05-13.00:59:29
SpamBayes Score
Marked as misclassified
Logged In: YES 

Well, if you were doing this with a list comprehension it isn't hard::

        float_list = [float(x) for x in mylist]
    except ValueError:
        print "The item %s in mylist is not a number." % x

Since list comprehensions are practically just a 'for' loop in a much tighter 
way the variables used stick around just as if you had used a 'for' loop.

The other issue is the way errors propogate in C.  If map were to return its 
own error specifying which item caused a problem it would have to overwrite 
the exception that was raised in the first place and overwriting exceptions on 
the whole is bad.

If you really are in love with map you can always define your own wrapper 
around float to raise the exception you want::

    def myfloat(num):
            return float(num)
        except ValueError:
            raise ValueError("The item %s in mylist is not a number." % num)

I personally feel this RFE should be rejected.  Anyone else agree?
Date User Action Args
2007-08-23 16:01:22adminlinkissue447143 messages
2007-08-23 16:01:22admincreate