- 论坛徽章:
- 0
|
anonymous0502 发表于 2012-04-12 12:22 ![]()
不同工具输出编码及处理方式不同吧
如何才能让cmd下面运行的1.py能够输出一个乱码,而不是抛出异常呢? 我尝试了decode的ignore参数,发现根本就不能ignore:
s=u'\x92'
print s.decode('utf-8','ignore')
这回在python shell里面都抛异常了:
>>>
Traceback (most recent call last):
File "D:\1.py", line 2, in <module>
print s.decode('utf-8','ignore')
File "C:\Python26\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode character u'\x92' in position 0: ordinal not in range(12
难道decode函数的'ignore’参数不能工作么? |
|