Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import unicodedata
- def is_number(s):
- try:
- float(s)
- return True
- except ValueError:
- pass
- try:
- unicodedata.numeric(s)
- return True
- except (TypeError, ValueError):
- pass
- return False
- for codepoint in range(2**16):
- chr_ = chr(codepoint)
- if chr_.isnumeric() and not chr_.isdigit():
- print(u'{:04x}: {} ({})'.format(codepoint, chr_,
- unicodedata.name(chr_, 'UNNAMED')))
- # Testing as a str
- print(is_number('foo'))
- print(is_number('1'))
- print(is_number('1.3'))
- print(is_number('-1.37'))
- print(is_number('1e3'))
- # Testing Unicode
- # 5 in Arabic
- print(is_number('٥'))
- # 2 in Thai
- print(is_number('๒'))
- # 4 in Japanese
- print(is_number('四'))
- # Copyright Symbol
- print(is_number('©'))
- # 44 in Japanese
- print(is_number('四四'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement