[Python Wpg] String to integer conversion
Stuart Williams
stuartw at mts.net
Tue Mar 28 21:38:52 EST 2006
>>>>> Mike Pfaiffer writes:
> Subject: [Python Wpg] String to integer conversion
> Is there a simple way to check if the value of the string is numeric
> first...
The try/except is better, but there is an isdigit method on strings
that's simpler than the regular expression, e.g.:
'123'.isdigit() -> True
'abc'.isdigit() -> False
'12a'.isdigit() -> False
' 3'.isdigit() -> False (try/except on int() handles white space)
Stuart.
More information about the Winnipeg
mailing list