3 Oct
2011
3 Oct
'11
4:52 p.m.
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