Python之禪,作者Tim Peters(The Zen of Python, by Tim Peters)
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
美麗的比丑陋的好。
Explicit is better than implicit.
明確的比隱含的好。
Simple is better than complex.
簡(jiǎn)單比復(fù)雜好。
Complex is better than complicated.
復(fù)雜總比難以理解好。
Flat is better than nested.?
扁平式比嵌套式更好。
Sparse is better than dense.?
稀疏的比密集的好。
Readability counts.??
可讀性很重要。
Special cases aren't special enough to break the rules.
特殊情況并不特殊,不足以打破規(guī)則。(此處規(guī)則指的是以上所列出的)
Although practicality beats purity.?
即使實(shí)用性勝過(guò)純潔性。
Errors should never pass silently.?
錯(cuò)誤也永遠(yuǎn)不應(yīng)該被忽略。
Unless explicitly silenced.
?除非明確表示要忽略。
In the face of ambiguity, refuse the temptation to guess.?
當(dāng)面對(duì)模棱兩可的問(wèn)題,要拒絕猜測(cè)的誘惑。
There should be one-- and preferably only one --obvious way to do it.
應(yīng)該有一個(gè)--最好只有一個(gè)--明顯的方法來(lái)做。
Although that way may not be obvious at first unless you're Dutch.?
雖然這種方式一開(kāi)始可能并不容易明白,除非你是荷蘭人。
Now is better than never. 現(xiàn)在做總比不做要好。
Although never is often better than *right* now.?
雖然“不做”通常不會(huì)讓你感受到“現(xiàn)在做”的痛苦
If the implementation is hard to explain, it's a bad idea.?
如果實(shí)施起來(lái)很難解釋,那肯定是個(gè)壞主意。
If the implementation is easy to explain, it may be a good idea.?
如果實(shí)施起來(lái)很容易解釋,這可能是一個(gè)好主意。
Namespaces are one honking great idea -- let's do more of those!
命名空間是一個(gè)偉大的想法 -- 讓我們做更多這樣的事情!"。
譯者注:
命名空間 (Namespace)是從名稱到對(duì)象的映射,大部分的命名空間都是通過(guò) Python 字典來(lái)實(shí)現(xiàn)的。 命名空間提供了在項(xiàng)目中避免名字沖突的一種方法。