貌似遇到了字符编码的坑了。。

2014 年 6 月 11 日
 shinerene
在python中的字符串是“这是一个字符串”,但是一旦输入到了浏览器中就是/xe03之类的,
已经尝试过
1.reload(sys)
sys.setdefaultencoding('utf-8')
2.# -*- coding: utf-8 -*-

均无法解决

请问有什么办法能解决么?
4088 次点击
所在节点    Python
8 条回复
sujin190
2014 年 6 月 11 日
json?
alexapollo
2014 年 6 月 11 日
u'这是一个字符串'
shinerene
2014 年 6 月 11 日
@alexapollo 又尝试了一下 发现好像是存入到了list中的原因,如果直接给a赋值 ”你好“,浏览器出书还是”你好“ ,但是如果把a存入到了list中 再打印出来就是/xe03之类的了
decken
2014 年 6 月 11 日
@shinerene 在列表里面的存储方式应该是utf8的吧
shinerene
2014 年 6 月 11 日
@decken 对的 我不是很理解,比如说a=“你好” 在终端中a = '\xe4\xbd\xa0\xe5\xa5\xbd'
但是print a就是你好。。。这是为什么呢。。
alexapollo
2014 年 6 月 11 日
list的话要先做一下escape unicode
yakczh
2014 年 6 月 11 日
换python3 一劳永逸地解决编码问题,不用再折腾填坑了
shinerene
2014 年 6 月 12 日
@alexapollo 已经解决~

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/116964

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX