Message53209
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? |
|
Date |
User |
Action |
Args |
2007-08-23 16:01:22 | admin | link | issue447143 messages |
2007-08-23 16:01:22 | admin | create | |
|