How to check if a string "is" an int?

David Rasmussen david.rasmussen at gmx.net
Wed Dec 21 17:31:26 EST 2005


Daniel Schüle wrote:
> 
> others already answered, this is just an idea
> 

I guess, if we want to avoid the exception paradigm for a particular 
problem, we could just do something like:

def isNumber(n):
     try:
         dummy = int(n)
	return True
     except ValueError:
         return False

and use that function from whereever in the program.

/David



More information about the Python-list mailing list