_=\'_=%r;print _%%_\';print _%_
Is this the shortest possible python quine, or can it be done better? This one seems to improve on all the entrie
Even shorter:
print(__file__[:-3])
And name the file print(__file__[:-3]).py
(Source)
Edit: actually,
print(__file__)
named print(__file__)
works too.
Both
print open(__file__).read()
and anything involving import are not valid quines, because a quine by definition cannot take any input. Reading an external file is considered taking input, and thus a quine cannot read a file -- including itself.
For the record, technically speaking, the shortest possible quine in python is a blank file, but that is sort of cheating too.
I'm just going to leave this here (save as exceptionQuine.py):
File "exceptionQuine.py", line 1
File "exceptionQuine.py", line 1
^
IndentationError: unexpected indent
I would say:
print open(__file__).read()
Source