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

发布时间 2023-03-26 15:02:37作者: Artwalker

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!

命名空间是一个伟大的想法 -- 让我们做更多这样的事情!"。

译者注:
命名空间 (Namespace)是从名称到对象的映射,大部分的命名空间都是通过 Python 字典来实现的。 命名空间提供了在项目中避免名字冲突的一种方法。