Avoiding "invalid literal for int()" exception
Fredrik Lundh
fredrik at pythonware.com
Tue Dec 12 05:29:36 EST 2006
Gabriel Genellina wrote:
>>> 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.
>
> Oh, I didn't know that last part! Thanks.
> I get a bit confused by the [0], thinking it was checking a single
> character.
if you really want to use isdigit(), writing
uniList[0].encode("ascii", "ignore").isdigit()
should solve the unicode issue, I think.
</F>
More information about the Python-list
mailing list