March 7, 2009 will

Live your life by the Tao of Python

As a Godless heathen, I have no scripture from which to guide me in my day-to-day life, and I must look for meaning elsewhere. I believe I have found that meaning in the most unlikely of places; the Python shell. If you enter import this in to the Python interpreter, it will reveal to you an ancient wisdom in the guise of a collection guidelines for the Python language.

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

I have studied these words for many years and have come to believe that they are in fact guidelines for living a fulfilling and successful life.

Beautiful is better than ugly.

As the first line in the Tao, this line must surely possess some special significance. The obvious interpretation would be to seek out that which is beautiful and reject that is ugly – but as anyone with experience of life knows, beauty does not always bring happiness. A deeper meaning must be sought.

I suspect that Beautiful is actually a mis-translation of Elegance, and ugly refers to the literal opposite of elegance. Elegance of course, can refer to many things that are harmonious together. Given these corrections, the meaning is clear; do not seek out the most beautiful woman, or the most beautiful car – they will not bring happiness. Seek out a woman and a car that possess elegance (not just beauty). The Tao brings us wise words indeed.

Explicit is better than implicit.

The Tao teaches us that it is better to be explicit in all things. A truism that can be found in religion: “Don’t hide your light under a bushel”, and conventional wisdom: “Don't ask, Don't get”. Although the Tao is true to its own words, and need not talk in allegories of bushels and lights. Explicit means being direct and not hiding ones intentions. If you want to leave with the most elegant woman, be direct.

Simple is better than complex.

In a world that seems to get more complex every year, the Tao tells us to prefer simplicity. Hows can this be so? Think back to when you were most happy and you will likely recall the time when things were most simple; most likely your childhood. Truly, simple brings happiness. Trust the Tao.

Complex is better than complicated.

The Tao recognizes that the cosmos is an imperfect place, and even though one may favor simplicity, complexity may still arise. The Tao also suggests that although complexity may be unavoidable, we often bring complicated upon ourselves. To elucidate; a girlfriend may be complex, but two girlfriends are complicated.

Flat is better than nested.

In life, there are many goals and tasks required to accomplish those goals. If we nest out task, that is start another task before fully accomplishing what we have started, then we will struggle to accomplish anything. The Tao tells us that it is better to be flat, and to fully achieve each goal before moving on to the next.

Achieving Enlightenment

Unfortunately, I can't divulge the rest of the secrets in the Tao, as to truly understand Tao, one must study it. I myself have yet to decipher it's full meaning, and some of it seems puzzling even to me; the Tao appears to indicate that only the Dutch can achieve true enlightenment.

Best of luck on your own quest for enlightenment, and remember: blessed are the geek, for they shall inherit the Earth.

Use Markdown for formatting
*Italic* **Bold** `inline code` Links to [Google]( > This is a quote > ```python import this ```
your comment will be previewed here
Eric O LEBIGOT (Eol)
The official text is the “Zen of Python”, and your blog talks about the “Tao of Python”: that's interesting! Laozi is supposed to have crossed from China to India, while Bodhidharma transmitted Zen from India to China: the connections between Tao and Zen are indeed quite strong…

It's true that by looking at Python code, you can guess some details about the author of the lines, and appreciate how close he is from the way…
As a joke its ok, but its scary how as soon as one tries using a computer joke as religious guidelines common tropes of religious thinking appear, the first of them was reinterpreting beautiful as elegant.

“If you want to leave with the most elegant woman, be direct.”.replace(“leave”, “live”)
And like most religious tracts, you can make it mean anything you want because it has to be interpreted and contains internal contradictions. Look at explicit self as the first argument to every method. It's a horrible design wart, and it's complicated, not simple (how many newbies a day get burned by the error message that claims the user supplied four arguments when they think they only supplied three?). But you can find lots of fanboys online who will talk about how it's great because explicit is better than implicit. But somehow they have no problem with the interpreter implicitly *supplying* that argument. Or a hundred other things in Python that are implicit.
Alex Martelli
I believe my wife Anna and I, at our marriage in 2004 (from where we flew right on to OSCON), were the first to use “The Zen of Python” as one of our marriage readings – see for the whole set. BTW, another reading was the start of what I believe is the earliest surviving book written to evangelize atheism – fittingly enough, it's an invocation to a Goddess;-).

So inspiring post …. Thanks :)
Juan Leotta

This is a beautiful post. Thank you, Juan