Search code examples
pythonquine

Is this a valid quine?


def start(fileName):
  fileReader = open(fileName)
  for row in fileReader:
    print row,

if __name__ == "__main__":
  import sys
  if len(sys.argv) <= 1:
    print "usage quine /path/to/file"
    sys.exit(-1)
  fileName = sys.argv[0]
  start(fileName)

python quine.py foo


Solution

  • No, a quine shouldn't take in any input:

    A quine takes no input. Allowing input would permit the source code to be fed to the program via the keyboard, opening the source file of the program, and similar mechanisms.

    From Quine (computing).

    UPDATE

    You need to encode the source into the quine itself. A quine consists of two parts: code that does the actual printing and data that represents the source code. It seems recursive, but isn't really. For a good quine tutorial, I recommend checking out this link; it's what I used to create a quine in a language that I designed.