I'm just curious if this exists. After programming python for the better part of a year I've never come across it.
Is there a python function that is c-compiled (for faster access in comprehensions) that checks an exception:
A function like the following:
def no_exception(function, *args, **kwargs):
try:
function(*args, **kwargs)
except Exception:
return False
return True
You could use it in this case
# values is full of data
new_values = [float(n) if no_exception(float, n) else n for n in values]