未分类

PEP 20 – Python的禅宗

勤劳的小蜜蜂 · 3月6日 · 2019年 · ·

什么是PEP?

PEP是Python Enhancement Proposals的缩写。一个PEP是一份为Python社区提供各种增强功能的技术规格,也是提交新特性,以便让社区指出问题,精确化技术文档的提案。

PEP 20也就是第20条

PEP 20

只要在Python IDE中输入import this回车,就会出现如下19句Python编程箴言

>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


'''
美丽胜过丑陋。
明了优于晦涩。
简洁胜于复杂。
复杂胜于繁琐。
扁平优于嵌套。(嵌套不要太多)
稀疏优于密集。(代码要有适当的间隔)
可读性很重要。
特殊情况不足以打破规则。
实用性胜过纯洁。
错误不应该默默地传递。
尽管实践大于理论,但错误不可置之不理,除非另有明确的要求。
面对模棱两可,拒绝猜测的诱惑。
一定有一个 - 而且是唯一的一个 - 最好的方法来做到这一点。
刚开始那种方法可能并不明显,除非你是Python之父。
现在比永远好。
做也许好过不做,但不假思索就动手还不如不做。
如果实施很难解释,这是一个坏主意。
如果实现很容易解释,那可能是个好主意。
命名空间是一个很棒的主意 - 我们应该多加利用!
'''

0 条回应