Error in accent in Python 2.7

-3

During the encoding (below) there is an error appearing in the accent of some words:

Note: I am using notepad ++ and run python 2.7 on windows cmd

Code:

# encoding: utf-8
import os, sys

print "EXPEDIÇÃO DE DESPACHO"

Exit:

λ python teste1.py
EXPEDIÇÃO DE DESPACHO

Image

Note:Icheckedthisquestioninanotherpostbutitdidnothelp: Encoding utf-8 allows accents?

    
asked by anonymous 30.08.2018 / 02:18

1 answer

1

Apparently in cmd with Python2.7 just use u"..." , like this:

print u"á é í"

Note that the document should also be saved in utf-8 without BOM

Using notepad ++ :

UsingSublimeText:

I tested it on the native%, but it did not work, I'll edit the answer as soon as I get a technical solution and a breakdown of what changes from python2.7 and 3.x, since 3.x works correctly without having to use the command cmd.exe .

In cmd it did not work, but in cmder it worked to use the chcp command before running python, so you can do this directly via script, eg:

# -*- coding: utf-8 -*-
import os, sys

os.system('@chcp 65001')

print "EXPEDIÇÃO DE DESPACHO"
print "expedição de despacho"

Result:

    
30.08.2018 / 04:42