by shigemk2

当面は技術的なことしか書かない

Python unicodeな文字列でreplaceとかformatとかやったときの挙動

unicodeな文字列でreplaceとかformatとかやったときの挙動

>>> a = "日本語".decode("utf-8")
>>> a
u'\u65e5\u672c\u8a9e'
>>> b = "{}".format(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)