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 # 就像命名空間就是一個絕妙的想法,應當多加利用