这是一个有效的奎因吗?
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不, quine 不应该接受任何输入:
来自Quine(计算)。
更新
您需要将源代码编码到 quine 本身中。 quine 由两部分组成:执行实际打印的代码和表示源代码的数据。这看起来是递归的,但实际上并非如此。对于一个好的 quine 教程,我建议查看此链接;我用它来用我设计的语言创建 quine。
No, a quine shouldn't take in any input:
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 无法访问文件系统,所以不行。正如维基百科所述,“允许输入将允许通过键盘将源代码提供给程序,打开程序的源文件,以及类似的机制。”。
参考:
维基百科:Quine(计算)
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)