3 ms·
Simply encode your unicode string in utf-8 and print the resulting bytestring. Simple, huh? Okay, say you don't want to do u"somestring".encode('utf-8') all th
by inklesspen 18y ago
Simply encode your unicode string in utf-8 and print the resulting bytestring. Simple, huh?
Okay, say you don't want to do u"somestring".encode('utf-8') all the time. Python has a set of classes that will wrap files and transparently encode and decode for you. And stdout is just another file.
import sys
import codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
line = u"\u0411"
print line