0

I was trying to replicate this example https://mail.python.org/pipermail/python-list/2012-May/624363.html

I'm brushing up on my python coding skills and was studying the various string methods, and I found the methods isdigit, isdecimal, and isnumeric interesting. The python docs don't provide many examples so I am making my own that I can review whenever I wish. The very first example shown at the above link fails in my python 3.5 console. The output looks like this:

>>> c = '\u2155'
>>> print(c)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files (x86)\Python35-32\lib\encodings\cp437.py", line 19, in
encode
    return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2155' in position
0: character maps to <undefined>

The following test with other fractions worked okay for me.

>>> value = '\u00BC'
>>> print(value)
¼
>>> value.isdecimal()
False
>>> value.isdigit()
False

What am I missing?

shawn1874
  • 1,288
  • 1
  • 10
  • 26
  • 1
    Your *console codec* can't handle all of Unicode in general, and that character specifically. Upgrade to Python 3.6, where Python bypasses the selected codec altogether and talks Unicode straight to Windows. – Martijn Pieters Jan 13 '17 at 17:19
  • Okay. Why don't you post that as an answer? That other thread is in fact the same kind of question but it does not have an accepted answer so that thread does me no good whatsoever. – shawn1874 Jan 13 '17 at 17:36
  • "accepted" just means that the OP had a preference for one of the answers. The lack of the accepted mark doesn't mean anything, really, always look at all answers (or at least the top 3) to see what applies best to your situation. Python 3.6 was not out yet when those answers were written, I've left a few comments for the authors there to give them a chance to update before I swoop in and post a new answer. – Martijn Pieters Jan 13 '17 at 17:39
  • Your console uses `cp437` (Code Page 437) which can't display this char - maybe try [Change default code page of Windows console to UTF-8](http://superuser.com/questions/269818/change-default-code-page-of-windows-console-to-utf-8) – furas Jan 13 '17 at 17:41

0 Answers0