Andrew Andrew - 7 months ago 99
Python Question

how to add to list Cyrillic symbols

So i have a problem that script doesn't add Cyrillic symbols to list, i'm getting this error:

Traceback (most recent call last): File
"c:\Users\Viktor\Desktop\Folder", line 23, in
print(list_script) File "C:\Users\Viktor\AppData\Local\Programs\Python\Python36-32\lib\encodings\",
line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in
position 6-11: character maps to

I found couple solutions on stack overflow, but they didn't work for me well

list1, list2 = ([] for i in range(2))

for dirpath, dirnames, filenames in os.walk('D:\\Folder'):
for fname in filenames:

for list_script in list1:

Answer Source

You could try set PYTHONIOENCODING enviroment variable to 'UTF-8':

os.environ["PYTHONIOENCODING"] = 'UTF-8'

or change stdout encoding:

sys.stdout = codecs.getwriter('utf8')(sys.stdout.buffer)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download