0

I try to write to txt file list with russian string.(I get that with unique1 = np.unique(df['search_term']), it's numpy.ndarray)

thefile = open('search_term.txt', 'w')
for item in unique1:
    thefile.write("%s\n" % item)

But in list this string looks correct. But after writing it looks like

 предметов berger bg bg045-14 отзывы
 звезд 
 воронеж

Why a get that?

ldevyataykina
  • 1,819
  • 6
  • 21
  • 42

1 Answers1

0

Try writing to the file like this:

import codecs

thefile = codecs.open('search_term.txt', 'w', encoding='utf-8')  
for item in unique1:
    thefile.write("%s\n" % item)

The problem is that the file likely is encoded correctly hence why the characters will display incorrectly.

Daniel Waghorn
  • 2,967
  • 2
  • 18
  • 32