The Zen of Python 《python之禅》 by Tim Peters

当我在读《Ryan Mitchell-Web Scraping with Python_ Collecting Data from the Modern Web-O'Reilly Media (2015)》(《python网络数据采集》)发现的Python’s most famous “Easter Egg”,试试在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.(注释1)

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之禅》  Tim Peters

优美胜于丑陋

明了胜于隐晦

简洁胜于复杂

复杂胜于混乱

扁平胜于嵌套

宽松胜于紧凑

可读性很重要

即便是特例,也不可违背这些规则

虽然现实往往不那么完美

但是不应该放过任何异常

除非你确定需要如此

如果存在多种可能,不要猜测

肯定有一种——通常也是唯一一种——最佳的解决方案

虽然这并不容易,因为你不是Python之父1

动手比不动手要好

但不假思索就动手还不如不做

如果你的方案很难懂,那肯定不是一个好方案

如果你的方案很好懂,那肯定是一个好方案

命名空间非常有用,我们应当多加利用

注 1: 这一行可能是指荷兰计算机科学家艾兹赫尔 • 戴克斯特拉(Edsger Dijkstra),他在 1978 年曾经说过:“我认为,编程语言设计的一个原则是……无论从哪一点来看,等价的程序不太可能有不一样的表示…… 但是,完全不同的编程方式增加了不必要性,因此妨碍了代码的维护效率、可读性等。”(http://www.cs.utexas.edu/~EWD/transcriptions/EWD06xx/EWD660.html)不过这句话可能就是指 Python 的发明人, Guido van Rossum,他也是荷兰人。不过好像没人能确定到底是哪一种情况。美国亚利桑那州全州不用夏令时,凤凰城是其州府。——译者注

你可能感兴趣的:(The Zen of Python 《python之禅》 by Tim Peters)