File output accentuation problem saved on equipment

Asked

Viewed 234 times

1

Good guys I have the following file saved in my equipment "names.txt", this one containing 1190 lines. Follow 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 continues like this, even tried using pprint in which the output was gross showing. Showing other characters in accent due to python recognizing only ASCII. Would anyone have any idea what might be going on.

  • I ran your code here and recognized the accents.

  • Strange, it could be then the output of ipython2. I will test here by the linux terminal.

  • I circled by the terminal.

  • circled here now, still continues with the bad exit. Z lio Zen bio Zeus

  • I honestly have no idea what it might be, I just opened the IDLE of python2.7 here, I wrote the code in the nail and the output still returns bad

  • 1

    Save the file nomes.txt as UTF8 without GOOD and try again.

  • @Guilhermenascimento solved that very thing

  • 1

    I use linux I did the following I opened the names.txt with gedit gave a save as, ai in gedit itself it has the options of which formatting use ai I put utf-8 and I went the code solved

  • @Glauciofonseca had forgotten about Gnome, I haven’t used liunx for a long time :)

  • 1

    @Guilhermenascimento actually don’t even use Gnome, I use Linux Arch with Xfce :)

  • @Glauciofonseca a sim é que a maioria dos ambientes Graficos tem algumas ferramentas do Gnome hehehehe, também gosto do Xfce :)

  • To this and truth, some always use a gnome tools same.

Show 7 more comments

1 answer

2


Save Document . txt as utf8 without GOOD and will solve.

  • Using Notepad++:

    utf8 sem bom notepad++

  • Using Sublime Text:

    utf8 sublime sublimetext

  • Vim:

    Define the fileencoding as utf8 (I believe I am already without GOOD)

    :set fileencoding=utf8
    :w arquivo.txt
    
  • what would this utf-8 GOOD

  • I found the answer http://answall.com/questions/16556/qual-a-diferen%C3%A7a-entre-arquivos-encodados-com-bom-e-sem-bom

  • @Glauciofonseca I will link later, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.