3 Oct
2011
3 Oct
'11
7:52 a.m.
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) 0.0
I think there are many use cases for this, every time float() or int() are called with data that cannot be guaranteed to be numeric, it has to be checked and some sort of default behaviour applied. The above example is just much cleaner than: try: return float(s) except ValueError: return 0.0 Any takers? David