这是有效的奎因吗?

2024-05-14 00:42:21 发布

您现在位置:Python中文网/ 问答频道 /正文

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


Tags: nameinforifmaindefsysopen
2条回答

不,奎因不能接受任何输入:

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.

来自Quine (computing)。在

更新

你需要把源代码编码成奎因本身。quine由两部分组成:执行实际打印的代码和表示源代码的数据。它似乎是递归的,但实际上不是。对于一个好的quine教程,我建议查看this link;这是我用来用我设计的语言创建quine的工具。在

Quines不能访问文件系统,所以不能。正如维基百科所说,“允许输入将允许源代码通过键盘、打开程序的源文件以及类似的机制输入程序。”。在

参考文献: Wikipedia: Quine (computing)

相关问题 更多 >