《The Zen of Python》——Python编程和设计的指导原则

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!

翻译:

The Zen of Python, by Tim Peters
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.
尽管解决方案可能不明显,除非你是Python之父(Guido van Rossum “龟叔” )

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、Python 库中WebSocket使用示例
https://www.onexin.net/latest/python-websocket/

转载请注明出处:https://www.onexin.net/latest/the-zen-of-python/

Leave a Reply

Your email address will not be published. Required fields are marked *