0

So I have a txt file that is written in Farsi and I want to split it word by word and put it in a list, which means I am going to have a list of Farsi words. The error I get:

UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-2: character maps to

code:

text_list = []
f = open('random.txt', encoding='utf-8')
text = f.read().split(' ')

for i in range(0, len(text)):
    text_list.append(text[i])
print(text_list)

Also, I've tried: pip install win-unicode-console Then:

try:
    from win_unicode_console import enable
    enable()
except ImportError:
    pass

It didn't work, Any suggestions??

  • 1
    See [this answer](https://stackoverflow.com/a/60634040/4582273) – lemonhead Aug 22 '21 at 10:26
  • Does this answer your question? [How to print utf-8 to console with Python 3.4 (Windows 8)?](https://stackoverflow.com/questions/25127673/how-to-print-utf-8-to-console-with-python-3-4-windows-8) – jonrsharpe Aug 22 '21 at 12:27
  • You can check the answer here: I hope this resolve your problem. https://stackoverflow.com/questions/39528462/python-3-print-function-with-farsi-arabic-characters Note: Maybe the problem is like the terminal that you are using is supporting the UTF-8 characters and that's why I don't print the Persian characters. – Usman Aug 22 '21 at 10:31

0 Answers0