导入此目的

cai*_*ing 9 python module

Python中有一个众所周知的Easter Egg 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!
Run Code Online (Sandbox Code Playgroud)

那究竟是什么目的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曾经说过为什么要把它包括在内吗?

E. *_*eme 9

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

"长期以来,Pythoneer Tim Peters简洁地将BDFL的设计指导原则引入了20个格言中,其中只有19个被写下来了."

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

遵循这些准则可能会提高Python代码的可读性,可用性和可维护性.其中任何一个看起来都"毫无用处".

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

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