I am looking for a way to print unicode characters to a UTF-8 aware Linux console, using Python 2.x's print
method.
What I get is:
$ python2.7 -c "print u'é'"
é
What I want:
$ python2.7 -c "print u'é'"
é
Python detects correctly that the console is configured for UTF-8.
$ python2.7 -c "import sys; print sys.stdout.encoding"
UTF-8
I have looked at 11741574, but the proposed solution uses sys.stdout
, whereas I am looking for a solution using print
.
I have also looked at 5203105, but using the encode
method does not fix anything.
$ python -c "print u'é'.encode('utf8')"
é
SOLUTIONS
As suggested by @KlausD. and @itzmeontv
$ python2.7 -c "print 'é'"
é
As suggested by @PM2Ring
$ python -c "# coding=utf-8
> print u'é'"
é
See the accepted answer for an explanation about the cause of the issue.