Avoiding "invalid literal for int()" exception
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Tue Dec 12 01:59:30 EST 2006
In <mailman.1415.1165879866.32031.python-list at python.org>, Gabriel
Genellina wrote:
> At Monday 11/12/2006 07:22, aine_canby at yahoo.com wrote:
>
>>elif int(uniList[0]) in range(0,10):
>
> Either of these will work to avoid an unneeded conversion:
>
> elif uniList[0] in "0123456789":
>
> elif uniList[0] in string.digits:
>
> elif uniList[0].isdigit():
The last does not work. Not only that it accepts numbers greater than 9
because it checks if the whole string consists of digits, it also accepts
u'²₂' and other unicode digits.
Ciao,
Marc 'BlackJack' Rintsch
More information about the Python-list
mailing list