s="""print '''s=%s%s%s
%s'''%('"'*3,s,'"'*3,s)"""
print '''s=%s%s%s
%s'''%('"'*3,s,'"'*3,s)
And this is just a one way to use it:
$ python printself.py | python | python | python | python | python | python | python | python
s="""print '''s=%s%s%s
%s'''%('"'*3,s,'"'*3,s)"""
print '''s=%s%s%s
%s'''%('"'*3,s,'"'*3,s)
Of course, you are free to choose your own way... :)
Someone might wonder, is this the shortest self-printing Python program. Well, it is not. The shortest one is just a bit boring.
$ touch shortest-one.py $ ls -l shortest-one.py -rw-r--r-- 1 ask ask 0 2006-11-02 00:04 shortest-one.py $ python shortest-one.py $ python shortest-one.py | python | python | python | python | python | python | python | python $
Back to my homepage.