开发者

Is this a valid quine?

开发者 https://www.devze.com 2023-01-03 18:48 出处:网络
def start(fileName): 开发者_开发问答 fileReader = open(fileName) for row in fileReader: print row,
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


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.


Quines can't access the filesystem, so no. As Wikipedia states, "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.".

Reference: Wikipedia: Quine (computing)

0

精彩评论

暂无评论...
验证码 换一张
取 消