在python shell中敲 import this会触发一个彩蛋,神奇的打印下面一段话:

The Zen of Python, 即python之禅, 1999年Tim Peters大牛总结的“武功心法”:

 >>> 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!

我在网上参考了别人的翻译,再结合我自己的理解翻译如下:

 >>> import this
The Zen of Python, by Tim Peters
#Python之禅, by Tim Perters 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!
#命名空间是绝妙的理念,我们应当多加利用
05-08 08:27