shortest python quine?

后端 未结 10 1804
天涯浪人
天涯浪人 2020-12-23 19:55
_=\'_=%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

10条回答
  •  猫巷女王i
    2020-12-23 20:37

    I am strictly against your solution.

    The formatting prarameter % is definitively a too advanced high level language function. If such constructs are allowed, I would say, that import must be allowed as well. Then I can construct a shorter Quine by introducing some other high level language construct (which, BTW is much less powerful than the % function, so it is less advanced):

    Here is a Unix shell script creating such a quine.py file and checking it really works:

    echo 'import x' > quine.py
    echo "print 'import x'" > x.py
    python quine.py | cmp - quine.py; echo $?
    

    outputs 0

    Yes, that's cheating, like using %. Sorry.

提交回复
热议问题