首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >艰难地学习Python -- python-3环境下的ex17.py

艰难地学习Python -- python-3环境下的ex17.py
EN

Stack Overflow用户
提问于 2019-05-21 11:07:52
回答 1查看 111关注 0票数 0

我尝试在python-3环境下学习这本书,但当我尝试运行它时,它弹出一个错误。有什么地方可以解决这个问题吗?

一旦我删除了

代码语言:javascript
复制
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()

代码运行得很完美。所以我认为应该是python2和python3之间的语法问题

代码语言:javascript
复制
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键继续运行。但实际上,代码停止了,并出现了一个名为

代码语言:javascript
复制
"Traceback (most recent call last):
  File "ex17.2.py", line 18, in <module>                                        g
    input("")
  File "<string>", line 0

    ^
SyntaxError: unexpected EOF while parsing

突然冒出来了。

EN

回答 1

Stack Overflow用户

发布于 2019-05-21 12:06:31

是的,你是对的!!您得到的错误是由于python版本更改造成的。此代码在python 3.x中运行良好,但在3.x以下的python版本中失败。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56230552

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档