Print your own code.
Magnus L. Hetland
mlh at idt.ntnu.no
Sun Sep 19 12:50:41 EDT 1999
François Pinard <pinard at iro.umontreal.ca> writes:
> nascheme at ucalgary.ca (Neil Schemenauer) writes:
>
> > >I heard that it's possible to write a python script that prints
> > >it's own source... is that true? How?
>
> > That is an old trick. I believe it can be done in almost any
> > language.
>
> There is an old theorem by Kleene about this (the fixed-point theorem). Gosh,
> this is really far in my memory -- no idea of what the theorem really says :-)
Being one of the (probably many) people who have done this in Python,
I would be quite interested in the theorem...
And - it is called quineing or something... And there is a web-page
for it somewhere... Oh, well. My version is:
python -c "x='python -c %sx=%s; print
x%%((chr(34),repr(x),chr(34))%s'; print x%(chr(34),repr(x),chr(34))"
Run it on the command-line (without the line break in the middle) and
your outpur should equal the comman. (This, of course, includes the
"python -c" bit...)
--
Magnus
Lie Please forward all spam to
Hetland uce at ftc.org
More information about the Python-list
mailing list