K
K
KorwinD2015-11-19 16:54:26
Python
KorwinD, 2015-11-19 16:54:26

What to do with encodings in python 3?

Actually, the program scans the folder using os.listdir() and outputs all files to the console, as soon as it reaches the "GoL - copy.dat" file, it gives an error

File "C:\Users\korwi\AppData\Local\Programs\Python\Python35-32\lib\encodings\cp866.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0 ]
UnicodeEncodeError: 'charmap' codec can't encode character '\u2014' in position
4: character maps to

When changing the encoding .encode() to "utf8", it starts to produce the string "GoL \xe2\x80\x94 \xd0\xba\xd0\xbe\xd0\xbf\xd0\xb8\xd1\x8f.dat"
The question is how to force the console to give out Russian letters and various characters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
newpy, 2015-11-19
@newpy

apparently because the console is not utf-8 encoding. In the Windows console before win10 there was generally cp866, in win10 it seems to have become win1251, it would be worthwhile to clarify then which system, whether that console. Because there are no problems with encodings in python3.
everything is fine in win10

import os
os.listdir()

Outputs
... 'Searches', 'SendTo', 'Tracing', 'Videos', 'main menu', 'My Documents', 'Templates' ..., 'GoL - copy.dat'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question