Advertisement
Guest User

Untitled

a guest
May 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. import unicodedata
  2.  
  3.  
  4. def is_number(s):
  5. try:
  6. float(s)
  7. return True
  8. except ValueError:
  9. pass
  10. try:
  11. unicodedata.numeric(s)
  12. return True
  13. except (TypeError, ValueError):
  14. pass
  15. return False
  16.  
  17. for codepoint in range(2**16):
  18. chr_ = chr(codepoint)
  19. if chr_.isnumeric() and not chr_.isdigit():
  20. print(u'{:04x}: {} ({})'.format(codepoint, chr_,
  21. unicodedata.name(chr_, 'UNNAMED')))
  22.  
  23.  
  24. # Testing as a str
  25. print(is_number('foo'))
  26. print(is_number('1'))
  27. print(is_number('1.3'))
  28. print(is_number('-1.37'))
  29. print(is_number('1e3'))
  30. # Testing Unicode
  31. # 5 in Arabic
  32. print(is_number('٥'))
  33. # 2 in Thai
  34. print(is_number('๒'))
  35. # 4 in Japanese
  36. print(is_number('四'))
  37. # Copyright Symbol
  38. print(is_number('©'))
  39. # 44 in Japanese
  40. print(is_number('四四'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement