File output accent problem saved on the device

1

Well, I have the following file saved on my device "names.txt", which contains 1190 lines. Here is my python2.7 code:

#/usr/bin/python env
# -*- coding: UTF-8 -*-

abrir = open("nomes.txt", "r")

for a in abrir:
    print a.strip()

abrir.close()

But when it shows me the output, some names with accents it comes in the following format:

T�ri
Thais
Thauany
Thayn�
Thelma
Tiana
Ticiana
Tricia
T�nia

I have tried putting u before and it continues like this, I even tried using pprint in which the output was grossly showing. Showing other characters in the accent, because python only recognizes ASCII. Someone would have an idea of what might be happening.

    
asked by anonymous 27.02.2016 / 17:13

1 answer

2

Save the document .txt as utf8 without BOM and it will resolve.

  • Using notepad ++:

  • UsingSublimeText:

  • I came:

    Set fileencoding to utf8 (I believe I'm out of BOM)

    :set fileencoding=utf8
    :w arquivo.txt
    
27.02.2016 / 17:47