Chen Yangjian's Blog

Carpe diem - Seize the day

Import This

| Comments

了解 Python 的童鞋应该都知道 the Zen of Python。查看的方法很简单,import this就可以。

% python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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!

Python 的早期开发者之一,Barry Warsaw 不久前写了篇博客特此说明了 import this 的由来。2001 年秋天的时候,Pycon 的前身 IPC 10(International Python Conference #10)的组织者 Foretec 希望为大会找个口号,而且希望从 Python 社区里头找。当时提交了至少 500 多个,绝大部分都很烂。Python 的主要开发者三个,Guido、Tim(the Zen of Python 就他的杰作)和作者 Barry,Guido 因为老婆临产几乎没心思搞这个,而 Tim 虽然嘴上说看这些鸟口号五分钟脑子就成了一坨屎但还是筛选出了相对好些的 100 多条。于是 Barry 就和 Tim 接着挑,最终在 “Bite off all you like - Chewing is optional” 和 “import this” 之间,选择了后者。

而后,Barry 就搞了个 this.py 偷偷放进 Python 发行版里头,不知是 Tim 还是 Guido 建议再把内容 rot13 一下,于是就有了现在的 import this

via

Comments