The Zen of Python (PEP-20)

The Zen of Python (PEP-20)

The PEP contains the index of all Python Enhancement Proposals which are known as PEPs. PEP numbers are assigned by PEP editors. Now somewhat you probably know what does it mean by “The Zen of Python (PEP-20)”.



Tim Peters introduced very interesting 20 new “guiding principles”. But only 19 principles have been officially written and accepted, which influences in Python programming language development. The last one- 20th principle, “for Guido to fill in” were not considered which was referred to Guido Van Rossum, the original author of the Python language.

Import this! What? Tim Peters says, just import this! It means importing “this” package – The Zen of Python theory! Go ahead and see the result by firing command “import this” on your python shell or command prompt.

The Zen of Python (PEP-20)

>>> 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!

Where is this.py?

You must have wondering from where this package is getting imported! You can easily find this! Since this is officially accepted, it is available with standard python.
File location might be differ depending on your installation and operating system. You can see the details by using this command. Here is my this.py file situated.
 >>> this
  < module 'this' from 'C:\\TekkieHead\\Programs\\Python\\Python37\\lib\\this.py'>
 >>>

What is exactly inside this.py?

It should be exactly same lines written with print command, I assumed. But there is totally different content present in the this.py file, may be in different language! Have a look at it and help me to recognize this language in the comment box.
Go to file location, write click and open (This.py) with IDLE or text or notepad++ or…
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]))
If you are lazy to find location for this.py, write click and open with idle, etc. 

Here is the trick for you! 

print(this.s) command prints the text content of this.py file.

>>> print(this.s)

Lets play with this !

While going through the Zen of Python notes, I have got something very interesting which you might love it! May be its good idea for you to try same lines and come up with the new interesting lines, of course I would love to read from you!
Here you go ! you-love-this
>>>import this
.
.
>>> love=this
>>> you=love
>>>
>>> love is love
True
>>> you is you
True
>>> love is you
True
>>> this is not you
False
>>> love is not you
False
>>> you is not love
False
>>> love is this
True
>>>

What is opposite of this? May be THAT !

Daniel Greenfeld come up with the sort of opposite theory of Zen of python called as The Anti-Zen of Python! This is exactly opposite of what Time Peter have introduced. Game of words!

The Anti-Zen of Python

You can have a look at the principles on your shell by importing that using command “import that.” That package is not distributed with standard Python.
If you still attempt to import that then you will get this error – ModuleNotFoundError: No module named ‘that’.
You need to install that package using pip.

Install that !

Open command prompt/terminal and follow these instructions –
H:\>pip install that
Collecting that
  Downloading https://files.pythonhosted.org/packages/64/72/12dc208c9086e2584f15f681fcd03c74179341d0295a6/that-1.0.7.tar.gz
Installing collected packages: that
  Running setup.py install for that ... done
Successfully installed that-1.0.7
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
H:\>
Oops..! I’ve got the warnings to upgrade the pip comand version. Don’t worry, if you also get one. Let’s continue to upgrade it or you may skip this!
H:\>python -m pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/d8/f3/413bab4ff08e1fc4828dfc59996d721917df25dceff/pip-19.0.3-py2.py3-none-any.whl (1.4MB)
    100% |████████████████████████████████| 1.4MB 6.4MB/s
Installing collected packages: pip
  Found existing installation: pip 18.1
    Uninstalling pip-18.1:
      Successfully uninstalled pip-18.1
Successfully installed pip-19.0.3
H:\>

Import that !

>>> import that

The Anti-Zen of Python, by Daniel Greenfeld

Ugly is better than beautiful.
Implicit is better than explicit.
Complicated is better than complex.
Complex is better than simple.
Nested is better than flat.
Dense is better than sparse.
Line code counts.
Special cases are special enough to break the rules.
Although purity beats practicality.
Errors should always pass silently.
Spelchek iz fur loosers.
In the face of ambiguity, one guess is as good as another.
There should be many ways to do it.
Because only a tiny minority of us are Dutch.
Get things running, then fix them later.
If the implementation is hard to explain, it's enterprisey.
If the implementation is easy to explain, it won't take enough time to do.
Namespaces are too hard, just use "from module import *"!
>>>

Photo Credits: Pixeles ; References: Python PEP-20  The Anit-Zen Python

Spread the love

Leave a Comment