python 之禅

2011-01-14 18:46

python 之禅

by

at 2011-01-14 10:46:49

original http://www.javaeye.com/topic/871002

之前在学习python的时候,看过python的八荣八耻,之后发现python 神奇之处,import this


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! 名称空间是一个好东西——让我们做更多那样的东西!




Don't reinvent the wheel

Before writing any code,
➔ ➔ ➔ ➔
Check Python's standard library.

Check the Python Package Index (the "Cheese Shop"):

http://cheeseshop.python.org/pypi

Search the web. Google is your friend.




python 八荣八耻
以动手实践为荣 , 以只看不练为耻;
以打印日志为荣 , 以单步跟踪为耻;
以空格缩进为荣 , 以制表缩进为耻;
以单元测试为荣 , 以人工测试为耻;

以模块复用为荣 , 以复制粘贴为耻;
以多态应用为荣 , 以分支判断为耻;
以Pythonic为荣 , 以冗余拖沓为耻;
以总结分享为荣 , 以X求其解为耻;

      <br><br>
      作者: <a href="http://edisonlz.javaeye.com">edisonlz</a> 
      <br>
      声明: 本文系JavaEye网站发布的原创文章,未经作者书面许可,严禁任何网站转载本文,否则必将追究法律责任!
      <br><br>
      <span style="color:red">
        <a href="http://www.javaeye.com/topic/871002" style="color:red">已有 <strong>1</strong> 人发表回复,猛击-&gt;&gt;<strong>这里</strong>&lt;&lt;-参与讨论</a>
      </span>
      <br><br><br>

JavaEye推荐