Python3 是真的比 Python2 爽多了。。

2018-02-13 00:09:01 +08:00
 PureWhite

自己用 Django 写了个后台,Python3 完全不用管字符编码 ,是真的爽。

8842 次点击
所在节点    Python
31 条回复
SingeeKing
2018-02-13 15:36:11 +08:00
我问一个无关问题。。。Python 2 的编码声明到底是什么原理

# coding: utf-8
# _*_ coding:utf-8 -*-
# coding=utf-8

都能用,而且 utf-8 和 utf8 也是一样的效果(并且 Python 中所有的字符串传入都可以通用)

所以编码声明到底是什么原理?为什么书写有这么多形式
twor
2018-02-13 15:39:13 +08:00
@SingeeKing
If a comment in the first or second line of the Python script matches the regular expression coding[=:]\s*([-\w.]+), this comment is processed as an encoding declaration; the first group of this expression names the encoding of the source code file. The encoding declaration must appear on a line of its own. If it is the second line, the first line must also be a comment-only line.

https://stackoverflow.com/questions/41680533/is-coding-utf-8-also-a-comment-in-python
twor
2018-02-13 15:41:17 +08:00
@SingeeKing 可能没有 get 到你到问题,忽略吧
SingeeKing
2018-02-13 15:53:18 +08:00
@twor #23 完美回答了我的问题!谢谢!
loading
2018-02-13 16:10:43 +08:00
我在 py2 学了编码,到 go 学到了类型…
julyclyde
2018-02-14 08:26:42 +08:00
@booty python3 不支持的都是你不需要用的库
aminic
2018-02-14 13:02:31 +08:00
只有 rust 才能解救编码问题
qq976739120
2018-02-14 13:35:33 +08:00
没用的啦,工作的话还是会要求你用 2 的
likuku
2018-02-14 19:40:52 +08:00
@booty

Python 3 Wall of Superpowers : http://python3wos.appspot.com/

绝大部分库都已经支持 py3
shamashii
2018-02-20 16:50:03 +08:00
endecode 低于折磨后的人来说,准确地讲是 3.6 版本开始好的
frostming
2018-02-23 17:18:58 +08:00
reload(sys)这方法总感觉脏,还会有其他问题出现

还是要有一个好习惯,除了输入输出,其余全部 unicode

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

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

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

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

© 2021 V2EX