Convert '165.0' to int

Frank Millman frank at
Sun Jul 24 04:36:31 EDT 2011

On Jul 23, 8:28 pm, rantingrick <rantingr... at> wrote:
> On Jul 23, 1:53 am, Frank Millman <fr... at> wrote:
> >--------------------------------------------------
> > The ideal solution is the one I sketched out earlier - modify python's
> > 'int' function to accept strings such as '165.0'.
> >--------------------------------------------------
> NO! You create your OWN casting function for special cases.
> PythonZEN: "Special cases aren't special enough to break the rules."


"Although practicality beats purity".

I know I am flogging a dead horse here, but IMHO, '165', '165.',
'165.0', and '165.00' are all valid string representations of the
integer 165.[1]

Therefore, for practical purposes, it would not be wrong for python's
'int' function to accept these without complaining.

Just for fun, imagine that this had been done from python 1.x. Would
people now be clamouring for this 'wart' to be removed in python 3, or
would they say 'yeah, why not?'.


[1] Don't ask me why anyone would do this. I am dealing with a third-
party product that does exactly that.

More information about the Python-list mailing list