python 2.7でunicodeの達人になる。
さくらのレンサバが実はpython 2.7 早く3化してほしいが、世の中なぜかレンサバにpython3を無理やりインストールしている。
% python
Python 2.7.16 (default, Sep 19 2019, 05:07:24)
[GCC 4.2.1 Compatible FreeBSD Clang 6.0.0 (tags/RELEASE_600/final 326565)] on freebsd11
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.getdefaultencoding()
'ascii'
#default は ascii それでは utf-8 を指定する。
>>> sys.setdefaultencoding('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setdefaultencoding'
# エラーになる。最初から入っているsysはutfを知らない。
# 但し、リロードすると使えるようになる。
>>> reload(sys)
<module 'sys' (built-in)>
>>> sys.setdefaultencoding('utf-8')
>>> sys.getdefaultencoding()
'utf-8'
>>>
#あっさり。
I love UTF