UnicodeEncodeError:' ascii'编解码器无法对位置14-20中的字符进行编码:序数不在范围内(128)

时间:2015-05-22 22:54:51

标签: python unicode encoding

写入这样的文件时出现此错误:     #logo .img { /* For Firefox specifically */ -moz-transform: scale(0.5,0.5); /* For the other browsers */ -ms-transform: scale(0.5,0.5); -webkit-transform: scale(0.5,0.5); transform: scale(0.5,0.5); } 问题是我在调用包含Unicode字符和默认" ascii"编码器不知道如何将它们编码为字节。我明白了。

然后我f.write(str(data))看到了令人讨厌的角色,我看不到任何东西。有没有办法检测到它?感谢。

根据Steven Kryskala的建议,我做了print unicode(data)[13:20]并得到了这个:

print repr(unicode(data))[13:21]

那有什么不好的?

1 个答案:

答案 0 :(得分:0)

替换为此尝试此

    f.write(data.encode())