Filed in: Projects.FathersDayQuine · Modified on : Wed, 17 Jun 09
Herein find a Python quine, made especially for my D'Ad on Fathers' D'Ay 2009. (Okay, may have overdone the apostrophe thing a bit...)
Here's how it works:
Just a comment.
The magic that makes it happen. s is assigned a string which is in fact a copy of the entire program. The %r is a string-formatting place holder.
Here, we print s, but not before substituting the Python "repr" of s in for %r. In Python, calling the repr() function on an object returns a string that could be executed by Python to produce the object. Thus, calling eval(repr(o)) on an object that properly supports repr will return a copy of itself. (eval() executes a string as Python source code.)