Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is "The Zen of Python" located in the CPython source code?

Tags:

python

You of course know what happens when you import this, but where is the Zen located in the interpreter source code?

I'd searched the string "Readability counts" in a local clone but haven't found anything relevant.

Searching "zen of python" site:hg.python.org in Google gives me no result at all.

like image 382
mmoya Avatar asked Dec 03 '13 01:12

mmoya


People also ask

How do I see Zen in Python?

Thanks to his contribution, anyone can view the Zen straight from the Python interpreter by typing import this : >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit.

Where is Python source code stored?

Python code is not compiled into machine-code. It is compiled into a special low-level intermediary language called bytecode that only CPython understands. This code is stored in . pyc files in a hidden directory and cached for execution.

Which module prints the Zen of Python when imported?

As soon as we'd chosen "import this" I realized we just had to implement it. Python 2.2 was about to be released and I proposed that we turn off check-in notifications and sneak in a "this.py" module which when imported just printed the Zen of Python.


1 Answers

There's a file called this.py in the Lib directory.

The string is encoded using ROT-13 so it's not searchable. The code to decode it is in the file.

like image 165
Mark Ransom Avatar answered Oct 09 '22 18:10

Mark Ransom