Python之禅

来自通约智库
跳转至: 导航搜索

3.5.1 Python之禅(The Zen of Python, by Tim Peters)

Python之禅是隐藏在Python语言中的彩蛋,是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.

尽管在开始时没有那么显而易见,除非你是个荷兰人。(Python创始人是个荷兰人,或是调侃复杂问题像是看荷兰语)

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!

命名空间是个超级棒的主意,让我们多一些这样的想法。


注:1,The Zen of Python来自于Python交互式解释器,输入import this,可得。

2,翻译:阿润Aaron。