Self Printing Programs in Python

Let’s talk about self printing programs (or, quines). A self printing program is, as is its name, self explanatory. Today I thought about how to implement a quine in Python, I whipped up a solution on my own and then posed the challenge to some people in the office. These are the results:

This is a companion discussion topic for the original entry at

Excellent post!

the smartass approach is the most pythonesque lol, i cannot even decipher the others!

The Smartass Approach really impressed me !!

Here is mine, a little bit longer but well designed :D Oh, it works in an interactive shell too !

print (lambda s:s.replace(chr(042), chr(047)) %s) ('print (lambda s:s.replace(chr(042), chr(047)) %%s("%s")')

In python 3, none but the exec method hold for print() update.

I know this post is ancient, but I have taken an interest in quines and have written my own.
_="print '_='+chr(34)+'{0}'.format(_)+chr(34)+'; exec(_)'"; exec(_)

If you're using Python 2.7 or better, you can lose the "0" in the "format" statement (or use the "%" operator which is available in earlier versions)

awesome post !