Pythonic way to determine if a string is a number
python at bdurham.com
python at bdurham.com
Mon Feb 16 00:37:22 EST 2009
John,
> Do you care about numbers that are representable as an int, but are treated as inf by float()?
>
> For example:
> | >>> s = '1' * 310
> | >>> float(s)
> | inf
> | >>> a = int(s)
> | >>> # OK
My code range checks all numbers once they've been parsed, so I don't
believe this will be a problem for me.
However, I appreciate you pointing out this behavior because I was
unaware of this subtle nuance. I'll make sure to add this to our code
review checklist.
Thanks for your feedback,
Malcolm
More information about the Python-list
mailing list