Pythonic way to determine if a string is a number

python at python at
Mon Feb 16 06:37:22 CET 2009


> 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,


More information about the Python-list mailing list