Fun with Python’s “import this”

Everyone knows that when you perform import this, in your Python script, you get a printout of The Zen of Python, by Tim Peters.

However, what else is there in the this module?

>>> import this
The Zen of Python, by Tim Peters
>>> help(this)
Help on module this:


    c = 97
    d = {'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', ...
    i = 25
    s = "Gur Mra bs Clguba, ol Gvz Crgref\n\nOrnhgvshy vf o...

It looks like The Zen of Python text is stored in the module as this.s in ROT-13 encrypted form. The table for decoding this text is stored in this.d.

What is the most Pythonic way to decode the text in this.s?

  1. Loop over the characters in this.s:
    [something(c) for c in this.s]
  2. Decode c if it is encoded (is in the this.d dictionary):
    [(this.d[c] if c in this.d else c) for c in this.s]
  3. The result of the comprehension is a list of characters. Make a string out of it:
    ''.join([(this.d[c] if c in this.d else c) for c in this.s])
  4. Now, print the result:
    print(''.join([(this.d[c] if c in this.d else c) for c in this.s]))

That’s all, folks!

Author: Omer Zak

I am deaf since birth. I played with big computers which eat punched cards and spew out printouts since age 12. Ever since they became available, I work and play with desktop size computers which eat keyboard keypresses and spew out display pixels. Among other things, I developed software which helped the deaf in Israel use the telephone network, by means of home computers equipped with modems. Several years later, I developed Hebrew localizations for some cellular phones, which helped the deaf in Israel utilize the cellular phone networks. I am interested in entrepreneurship, Science Fiction and making the world more accessible to people with disabilities.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: