python里隐藏的“禅”

在 python的lib目录里有一个:this.py,它其实是隐藏着一首诗,源码如下:

代码如下:

s = “””gur mra bs clguba, ol gvz crgref

ornhgvshy vf orggre guna htyl.rkcyvpvg vf orggre guna vzcyvpvg.fvzcyr vf orggre guna pbzcyrk.pbzcyrk vf orggre guna pbzcyvpngrq.syng vf orggre guna arfgrq.fcnefr vf orggre guna qrafr.ernqnovyvgl pbhagf.fcrpvny pnfrf nera’g fcrpvny rabhtu gb oernx gur ehyrf.nygubhtu cenpgvpnyvgl orngf chevgl.reebef fubhyq arire cnff fvyragyl.hayrff rkcyvpvgyl fvyraprq.va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.gurer fubhyq or bar– naq cersrenoyl bayl bar –boivbhf jnl gb qb vg.nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh’er qhgpu.abj vf orggre guna arire.nygubhtu arire vf bsgra orggre guna *evtug* abj.vs gur vzcyrzragngvba vf uneq gb rkcynva, vg’f n onq vqrn.vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.anzrfcnprf ner bar ubaxvat terng vqrn — yrg’f qb zber bs gubfr!”””

d = {}for c in (65, 97): for i in range(26): d[chr(i+c)] = chr((i+13) % 26 + c)

print “”.join([d.get(c, c) for c in s])

输出结果为:(翻译自it柏拉图)

代码如下:

the zen of python, by tim peters《python 的禅》 by 提姆·彼特

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!命名空间是一个让人尖呼的伟大构想 —— 我们应该在那方面做得更多!

作者果然是很有“湿”意呀!!

Posted in 未分类

发表评论