1 import this 2 3 The Zen of Python, by Tim Peters 4 # python的设计哲学, 做者:Tim Peters 5 6 Beautiful is better than ugly. 7 # 优雅胜于丑陋(Python 以编写优美的代码为目标) 8 9 Explicit is better than implicit. 10 # 明确胜于含糊晦涩(优美的代码应当是明了的,命名规范,风格类似) 11 12 Simple is better than complex. 13 # 简单胜于复杂(优美的代码应当是简洁的,不要有复杂的内部实现) 14 15 Complex is better than complicated. 16 # 复杂胜于凌乱(若是复杂不可避免,那代码间也不能有难懂的关系,要保持接口简洁) 17 18 Flat is better than nested. 19 # 扁平胜于嵌套(优美的代码应当是扁平的,不能有太多的嵌套) 20 21 Sparse is better than dense. 22 # 间隔胜于紧凑(优美的代码有适当的间隔,不要奢望一行代码解决问题) 23 24 Readability counts. 25 # 可读性很重要(优美的代码是可读的) 26 27 Special cases aren't special enough to break the rules. 28 # 即使假借特例的实用之名,也不该打破这些原则(这些规则至高无上) 29 30 Although practicality beats purity. 31 # 尽管实践大于理论 32 33 Errors should never pass silently. 34 # 错误不可置之不理,除非你肯定须要这样作(精准地捕获异常,不写 except:pass 风格的代码) 35 36 Unless explicitly silenced. 37 # 除非另有明确要求 38 39 In the face of ambiguity, refuse the temptation to guess. 40 # 面对模棱两可(有歧义),拒绝猜想 41 42 There should be one-- and preferably only one --obvious way to do it. 43 # 而是尽可能找一种,最好是惟一一种容易的解决方案(若是不肯定,就用穷举法) 44 45 Although that way may not be obvious at first unless you're Dutch. 46 # 虽然这种方式开始时并不容易,除非你是 Python之父(这里的 Dutch 是指 Guido ) 47 48 Now is better than never. 49 # 但从如今就开始这么作,总比永远都不作好 50 51 Although never is often better than *right* now. 52 # 尽管常常有时 “没有作” 反倒比 “如今立马作“ 结果要好 53 54 If the implementation is hard to explain, it's a bad idea. 55 # 若是一个实现不容易解释,那么它确定是个坏主意 56 57 If the implementation is easy to explain, it may be a good idea. 58 # 若是一个实现很容易解释,那么它也许是个好主意 59 60 Namespaces are one honking great idea -- let's do more of those! 61 # 就像命名空间就是一个绝妙的想法,应当多加利用