This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brett.cannon
Recipients
Date 2003-05-13.00:59:29
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=357491

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

    try:
        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):
        try:
            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?
History
Date User Action Args
2007-08-23 16:01:22adminlinkissue447143 messages
2007-08-23 16:01:22admincreate