Home python Python displays strange characters

Python displays strange characters

Author

Date

Category

There is such a code:

from time import sleeep
Word = ""
Words = []
DATA = OPEN ('DICT.TXT', 'R')
d = str (data.read ())
Print (D)
for sym in d:
  # Print (SYM)
  IF Sym == ',':
    Print (Word)
    Words.APPEND (Word)
    Word = ""
  ELIF Sym == ".":
    Print (Word)
    Words.APPEND (Word)
    Break
  ELSE:
    Word = Word + Sym
For w in Words:
  Print (W)
  Sleep (0.7 * Len (w))

and .txt Document with defined Russian words written through the comma and space. When I start the script instead of Russian characters, this is:

їWITHђіμWITH ,, їѕє°.
їWITHђіμWITH,
 їѕє°
їWITHђіμWITH,
 їѕє°

What should I do to show words in Russian, instead unknown what?


Answer 1, Authority 100%

Let’s look at the scheme from the article “How to recognize krakoyarbra? “:

We see that it is UTF-8, decoded as Win-1251.

Indicate the correct encoding when you open the file

data = open ('dict.txt', 'r', encoding = 'utf-8')

Voila.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions