Skip to content

Instantly share code, notes, and snippets.

@grodtron
Created December 3, 2011 06:20
Show Gist options
  • Save grodtron/1426274 to your computer and use it in GitHub Desktop.
Save grodtron/1426274 to your computer and use it in GitHub Desktop.
A quick quine in python. The long one I wrote, the short one I found.
print (lambda x:x+repr((x,)))('print (lambda x:x+repr((x,)))',)
c = []
c.append('c = []')
c.append('f = lambda k: "c.append(" + repr(k) + ")"')
c.append('print c[0]')
c.append('print f(c[0])')
c.append('for line in c[1:]:')
c.append(' print f(line)')
c.append('for line in c[1:]:')
c.append(' print line')
f = lambda k: "c.append(" + repr(k) + ")"
print c[0]
print f(c[0])
for line in c[1:]:
print f(line)
for line in c[1:]:
print line
# re-execute the program's output a bunch of times and then write the result to a new file
python quine.py | python | python | python | python | python > quineoutput.py
# there should be no difference between the output and the original file!
echo "begin diff:"
diff quine.py quineoutput.py
echo "end diff"
# clean up
rm quineoutput.py
@inxanedev
Copy link

import sys;print(open(sys.argv[0],'r').read())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment