I am switched from Python 2.7 to Python 3.6.
I have scripts that deal with some non-English content.
I usually run scripts via Cron and also in Terminal.
I had UnicodeDecodeError in my Python 2.7 scripts and I solved by this.
# encoding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
Now in Python 3.6, it doesnt work. I have print statements like print("Here %s" % (myvar))
and it throws error. I can solve this issue by replacing it to myvar.encode("utf-8")
but I don't want to write with each print statement.
I did PYTHONIOENCODING=utf-8
in my terminal and I have still that issue.
Is there a cleaner way to solve UnicodeDecodeError
issue in Python 3.6?
is there any way to tell Python3 to print everything in utf-8? just like I did in Python2?
sys.stdout
). Can you provide whatsys.stdout.encoding
is set to on your machine? – AlfeTERM
to something likexterm
or similar. Also theLANG
variable could have an influence. – Alfe