2013/12/08: Python isdigit() and numerals

In python, strings have a predicate isdigit() indicating that the string consists of digits only. This predicate knows about specials symbols, like the superscript-digit-3, which is a digit.

Integer numerals, on the other hand, are formed of the symbols '0' to '9' only. So, not everything that isdigit() can be converted to an int.


~>python
Python 2.7.6 (default, Nov 30 2013, 14:16:15) 
[GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd8
Type "help", "copyright", "credits" or "license" for more information.
>>> a='10\xc2\xb3'
>>> b=a.decode('utf8')
>>> b
u'10\xb3'
>>> b.isdigit()
True
>>> int(b)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '10\xb3'
>>>