Pythonのお勉強 Part16
■ このスレッドは過去ログ倉庫に格納されています
0870デフォルトの名無しさん
2007/02/08(木) 13:38:01ipython 0.7.3 + python 2.5 ですが。
In [23]: s = '�@'.decode('cp932'); print s, type(s), hex(ord(s))
�@ <type 'unicode'> 0x2460
これあってますよね。でも
In [24]: s = u'�@'; print s
<type 'exceptions.UnicodeEncodeError'>: 'cp932' codec can't encode character u'\x87' in po
sition 0: illegal multibyte sequence
In [27]: print type(s), hex(ord(s[0])*0x100+ord(s[1]))
<type 'unicode'> 0x8740
タイプはunicodeなのにコードはsjis。どうして?
python 2.5だと
>>> s = '�@'.decode('cp932'); print s, type(s), hex(ord(s))
�@ <type 'unicode'> 0x2460
>>> s = u'�@'; print s, type(s), hex(ord(s))
�@ <type 'unicode'> 0x2460
で望んだ結果になるんですけど。
■ このスレッドは過去ログ倉庫に格納されています