[Python Wpg] String to integer conversion

Stuart Williams stuartw at mts.net
Wed Mar 29 04:38:52 CEST 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