python编码有关问题

python编码问题求助print (Content-Type:text/htmlcharsetutf-8\n)print (meta http-equivContent

python编码问题求助
print ("Content-Type:text/html;charset=utf-8\n")
print ("<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>\n");
print("a哈哈")

在IE中查看的时候,中文“哈哈”怎么变成乱码了?

[解决办法]
不要在代码里写中文。

Python code
print('a\xe5\x93\x88\xe5\x93\x88')
[解决办法]
如果你的脚本编码为 UTF-8,则:
print ("Content-Type:text/html;charset=utf-8\n")
print ("<meta http-equiv='Content-Type' content='text/html;charset=gb18030'>\n");
print("a哈哈".decode().decode('utf-8'))

如果你的脚本编码为 GBK,则:
print ("Content-Type:text/html;charset=utf-8\n")
print ("<meta http-equiv='Content-Type' content='text/html;charset=gb18030'>\n");
print("a哈哈")

大概是这样吧
[解决办法]
探讨

Python code

print(u"a哈哈")



这样试试