Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

edited title
Link
cpx
  • 17.7k
  • 21
  • 95
  • 152

UnicodeEncodeError in Python on Windows Console

Source Link
cpx
  • 17.7k
  • 21
  • 95
  • 152

UnicodeEncodeError in Python

I'm having the following error while recursing the files in a directory and printing file names in the console:

Traceback (most recent call last):
 File "C:\Program Files\Python33\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 '\u2013' in position
53: character maps to <undefined>

According to the error, one of the characters in the file name string is \u2013 which is an EN DASH character different from the commonly seen - minus character.

I have checked my Windows encoding which is set to 437. Now, I see that I have two options to workaround this by either changing the encoding of Windows console or convert the characters in get from the file names to suit the console encoding. How would I go do that in Python 3.3?

lang-py

AltStyle によって変換されたページ (->オリジナル) /