我尝试在python-3环境下学习这本书,但当我尝试运行它时,它弹出一个错误。有什么地方可以解决这个问题吗?
一旦我删除了
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()代码运行得很完美。所以我认为应该是python2和python3之间的语法问题
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print("Copying from %s to %s" % (from_file,to_file))
# we could do these two on one line too, how?
in_file = open(from_file)
indata = in_file.read()
print("The input file is %d bytes long" % len(indata))
print("Does the output file exist? %r" % exists(to_file))
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()
out_file = open(to_file, 'w')
out_file.write(indata)
print("Alright, all done")
out_file.close()
in_file.close()当我尝试运行它时,它应该在input()处停止,并等待我按return键继续运行。但实际上,代码停止了,并出现了一个名为
"Traceback (most recent call last):
File "ex17.2.py", line 18, in <module> g
input("")
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing突然冒出来了。
发布于 2019-05-21 12:06:31
是的,你是对的!!您得到的错误是由于python版本更改造成的。此代码在python 3.x中运行良好,但在3.x以下的python版本中失败。
希望这能有所帮助。
https://stackoverflow.com/questions/56230552
复制相似问题