导入此目的

时间:2017-04-23 22:55:37

标签: python module

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)无用模块的目的究竟是什么? Guido Van Rossum有没有说过为什么要把它包括在内?

1 个答案:

答案 0 :(得分:8)

引用与此相关的Python Enhancement Proposal(PEP): https://www.python.org/dev/peps/pep-0020/

  

“很长一段时间,Pythoneer Tim Peters简洁地引导了BDFL的指导   Python的设计原则为20个格言,其中只有19个   已被写下来。“

因此,本模块的既定目的是详细说明与Python代码开发相关的指南。

遵循这些指南可能会提高Python代码的可读性,可用性和可维护性。其中任何一个看起来都“毫无用处”。

注1:产生此指南列表的代码故意破坏其中的大部分。 =)

注2:BDFL代表Benevolent Dictator for Life,指的是Python的开发者Guido van Rossum。

相关问题