The best kittens, technology, and video games blog in the world.

Friday, September 06, 2013

Python 3 Unicode apparently no longer sucks

Hunted by kaibara87 from flickr (CC-BY)

I wrote jrpg as a Python 2 game that uses Unicode a lot everywhere, and I really hated Python 2's extremely shitty Unicode support. The following program:

# -*- coding: utf-8 -*-
print u"Hello, 東京"

Printed everything fine if you ran it on a terminal - but instantly crashed with retarded UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128) exception if you tried to pipe its output into any file or command.

I'm happy to say that Python 3 no longer suffers from this problem. The following program works fine in all contexts, and no longer even needs the silly annotations.

print("Hello, 東京")

If only all other problems fixed themselves while I wasn't looking...


Anonymous said...

is buggy and should be
#!/usr/bin/env python2

same thing with
#!/usr/bin/env python3

Remember, on modern UNIX, python is usually in /usr/local/bin/ not /usr/bin

taw said...

Anonymous: On OSX it's all over the place because OSX package management in a sticking pile of shit, on Linux it's definitely in /usr/bin/