David Townshend wrote:
My idea is fairly simple: add a "default" argument to int and float, allowing a return value if the conversion fails. E.g:
float('cannot convert this', default=0.0)
I think I'd be more likely to want to report an error to the user than to blindly return a default value.
If I did want to do this, I'd be happy to write my own function for it.
It could even be made generic:
def convert(text, func, default): try: return func(text) except ValueError: return default