Skip to main content

python 禪學

· 3 min read

任何安裝好的 python 版本中都包含著 python 禪學 (哲學), 在任何 python 互動介面 (如 IDLE) 中輸入

import this

則會出現如下的 python 禪學 (哲學)

Python 禪學 (pythoon Zen)

美觀的比醜陋的好 (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!)

--Tim Peters (gasolin 翻譯)

2007/03/01 更新: 參考 http://wiki.python.org.tw/The_Zen_Of_Python 其他人的理解修改