[Python-Dev] Rounding float to int directly (Re: struct module and coercing floats to integers)
James Y Knight
foom at fuhm.net
Thu Aug 3 05:39:43 CEST 2006
On Aug 2, 2006, at 11:26 PM, Raymond Hettinger wrote:
> Also, -10 on changing the semantics of int() to round instead of
> truncate. The truncating version is found is so many other languages
> and book examples, that it would be a disaster for us to choose a
> different meaning.
I'd be happy to see floats lose their __int__ method entirely,
replaced by an explicit truncate function.
I've always thought it quite a hack that python floats have implicit
truncation to ints, and then a random smattering of APIs go to extra
lengths to explicitly prevent float.__int__ from being called because
people thought "passing a float makes no sense!". That's right, it
doesn't, and it _never_ should happen implicitly, not just in those
particular few cases. Explicit is better than implicit.
James
More information about the Python-Dev
mailing list