作者coscell (顾人怨)
看板Python
标题Re: [问题] 新手请教:如何印出字码?
时间Thu Oct 29 09:56:48 2009
※ 引述《coscell (顾人怨)》之铭言:
: 标题: [问题] 新手请教:如何印出字码?
: 时间: Thu Oct 29 08:30:32 2009
:
: #coding=big5
: a=u'大家好'
: for i in a:
: print hex(ord(unicode(i))),
:
: 可以顺利印出 0x5927 0x5bb6 0x597d
: 如果把 a 改由使用者输入:
: a=raw_input('请输入文字: ')
: 输入 大家好 会产生错误:
:
: Traceback (most recent call last):
: File "a", line 4, in <module>
: print hex(ord(unicode(i))),
: UnicodeDecodeError: 'ascii' codec can't decode byte 0xa4 in position 0: ordinal
: not in range(128)
:
: 请问要如何修改?感谢指点!
:
: --
:
※ 发信站: 批踢踢实业坊(ptt.cc)
: ◆ From: 203.72.64.249
: 推 StubbornLin:u'请输入文字: ' 10/29 09:35
: → StubbornLin:unicode已经快成月经文了= = 10/29 09:35
还是错:
a=raw_input(u'请输入文字: ')
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordin
al not in range(128)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.130.1.79