Realcodeart.com

Zen of Python

Nineteen lines, hidden in a file, printed by a joke import.

Tim Peters, PEP 20. File this.py.

Get it on a mug or tee →

Tim Peters wrote the Zen of Python as a set of preferences, not as a law. He posted it in 1999. It later became PEP 20, a Python Enhancement Proposal that does not enhance the parser. It enhances the argument. When an API feels wrong, a Python programmer reaches for one of its lines the way a cabinetmaker reaches for a straightedge. Explicit is better than implicit. Simple is better than complex. Readability counts. Those preferences are not enforced by the compiler. They are enforced by code review, and by the mild shame of having written something the Zen would mock.

The document is short, nineteen aphorisms, and it includes its own shrug. Special cases are not special enough to break the rules, and then, immediately, practicality beats purity. The text knows that a slogan is a bad policeman. Namespaces are a honking great idea. The Dutch, in one line, are trusted. None of this is a specification of syntax. It is a record of what Peters thought the language was trying to be, written after the language had already shipped and gathered a style.

CPython hides the text in Lib/this.py so that the file does not spoil the joke. The string is encoded with ROT13, a cipher that is not a cipher. Each letter moves thirteen places. Apply it twice and the text returns. import this decodes the string and prints it. The implementation is a few lines around that string: an alphabet, a translation, a print. Barry Warsaw's era of the PEP process is what put the joke in the standard library as a numbered proposal. The number, 20, is low, which is the developers' way of saying the document is old and basic.

The bars are the whole file, encoded text included. The long string reads as one green run, because a string is a string even when it is rotated. The decoder reads as the short lines around it. You can see the joke without being able to read it. That is the correct amount of legibility for this object. The Zen itself is not printed on the mug as sentences. A person who wants the sentences can type two words at a prompt. A person who wants the shape of the hiding place can look at the bars.

The Python Software Foundation holds a copyright in the file, dated in the notice to 2001, under the PSF License Version 2. The notice is on the product page. It is short, and it is still a notice rather than a public-domain grant. This piece is marked accordingly. Clear, on this site, means the authors gave the work away with no conditions. The PSF did not. The license allows use. It asks the notice to be respected. The page does that. The shirt does not pretend to be a license exhibit.

There is a reason the encoded form is the portrait rather than a typeset poster of the aphorisms. A poster would be a quotation. A quotation of the whole Zen would be the poem, and the poem is the foundation's text. The file is a program that reveals the poem if you ask. The bars are that program. Green for the hidden string, other colors for the machinery that hides it, gray if a comment is in the excerpt. The import remains the ceremony. New programmers still run it, still laugh once, and then, if the language takes, start using the lines without running the file. The file stays in the tree anyway, a joke that became a landmark, and a license that stays on the page beside the cup.

Peters was already the author of timsort, the sorting algorithm Python adopted, and of a great deal of the standard library's practical taste. The Zen is the part that escaped the library and became folklore. People embroider it, misquote it, and invoke it against features they dislike. The file does not settle those fights. It prints the text and exits. The bars preserve the asymmetry that matters: almost the whole picture is one encoded literal, and the behavior is a thin frame around it. That is a fair portrait of a joke that became a constitution.

The PSF notice does not ask the mug to reproduce the nineteen lines. It asks for the license terms to remain available with the work. They remain available here. A visitor who came for a gift and stays for the history gets both the cipher and the reason the cipher is not public domain.

Mug and tee of Zen of Python