Python中有一个众所周知的复活节彩蛋,名为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!
那么this
的目的到底是什么?
它还包含4个变量:
this.c
包含数字97
this.s
包含The Zen of Python
编码在rot13
中this.i
包含数字25
this.d
包含以下字典:{'G': 'T', 'z': 'm', 'C': 'P', 't': 'g', 'F': 'S', 'p': 'c', 'o': 'b', 'P': 'C', 'V': 'I', 'T': 'G', 'Q': 'D', 'W': 'J', 'R': 'E', 'i': 'v', 'M': 'Z', 'w': 'j', 'O': 'B', 'L': 'Y', 'n': 'a', 'd': 'q', 'D': 'Q', 'K': 'X', 'H': 'U', 'S': 'F', 'N': 'A', 'A': 'N', 'B': 'O', 'v': 'i', 'a': 'n', 'I': 'V', 'J': 'W', 'u': 'h', 'q': 'd', 'j': 'w', 'e': 'r', 'x': 'k', 's': 'f', 'X': 'K', 'E': 'R', 'm': 'z', 'h': 'u', 'g': 't', 'y': 'l', 'U': 'H', 'c': 'p', 'r': 'e', 'f': 's', 'l': 'y', 'b': 'o', 'Y': 'L', 'k': 'x', 'Z': 'M'}
那么,这个(IMO)无用模块的实际用途是什么?吉多·范·罗森有没有说过他为什么要把它包括在内?
引用与此相关的Python增强建议(PEP): https://www.python.org/dev/peps/pep-0020/
因此,本模块的目的是阐明与Python代码开发相关的指导原则。
遵循这些准则可能会提高Python代码的可读性、可用性和可维护性。没有一个看起来是“无用的”。
注1:生成此指南列表的代码故意破坏了其中的大部分。=)
注2:BDFL代表仁慈的终身独裁者,指的是Python的开发者Guido van Rossum。
相关问题 更多 >
编程相关推荐