请教python中如何设置编码可以正确的显示中文?


图片

使用 python2.7 时,经常打印出来的结果是类似16进制的,请教如何设置编码可以打印出正常的中文?

python scrapy

HIGHKGB 9 years, 3 months ago

CMD环境的编码是CP936, 如果是Unicode字符串, 你可以尝试转换为GBK字符串, .encode('gbk')

吱喲喲的鱼竿儿 answered 9 years, 3 months ago

显示的unicode字符串,直接打印即可


 In [1]: print u'<title>\n\u8c46\u74e3 ...</title>'
<title>
豆瓣 ...</title>

zybwh answered 9 years, 3 months ago

Your Answer