How to check if a string "is" an int?
Erik Max Francis
max at alcyone.com
Wed Dec 21 05:20:17 EST 2005
pinkfloydhomer at gmail.com wrote:
> How do I check if a string contains (can be converted to) an int? I
> want to do one thing if I am parsing and integer, and another if not.
try:
x = int(aPossibleInt)
... do something with x ...
except ValueError:
... do something else ...
--
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
May it not be that, at least, the brighter stars are like our Sun,
the upholding and energizing centres of systems of worlds, adapted to
More information about the Python-list
mailing list