[Python-ideas] Default return values to int and float
Dirkjan Ochtman
dirkjan at ochtman.nl
Mon Oct 3 14:11:21 CEST 2011
On Mon, Oct 3, 2011 at 14:06, Mark Dickinson <dickinsm at gmail.com> wrote:
> But the two versions you give aren't equivalent. With:
>
> pv = float(ln['PV']) if ln['PV'] else None
>
> we'll get a ValueError if ln['PV'] contains some non-float, non-empty
> garbage value. With:
>
> pv = float(ln['PV'], default=None)
>
> and (IIUC) the proposed semantics, that garbage value will be turned
> into None instead, which is definitely not what I'd want to happen in normal usage.
Yeah, I guess you're right, and I'd definitely not want unexpected
garbage values to go unnoticed.
Cheers,
Dirkjan
More information about the Python-ideas
mailing list