
I don't think David is arguing for the default behavior to change -- merely that you get a dict.get style default. Kinda similar to getattr/2 raising AttributeError, and getattr/3 returning the default value.
cheers lvh
On 03 Oct 2011, at 12:40, Greg Ewing wrote:
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
-- Greg _______________________________________________ Python-ideas mailing list Python-ideas@python.org http://mail.python.org/mailman/listinfo/python-ideas