[Python-ideas] Default return values to int and float

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Oct 3 22:52:28 CEST 2011


Dirkjan Ochtman wrote:

> Hmm, not really true in my experience. Here's some actual code from my
> codebase at work:
> 
> v = float(row[dat]) if row[dat] else 0.0
> d.append(float(row[t]) if row[t] else 0.0)
> gen = (float(i) if i != '.' else None for i in row[1:])

This is different. You're looking for a particular value
(such as an empty string or None) and treating it as equivalent
to zero.

That's not what the OP suggested -- he wants *any* invalid
string to return the default value. That's analogous to
using a bare except instead of catching a particular
exception.

-- 
Greg



More information about the Python-ideas mailing list