gpt4 book ai didi

python - 读取文本文件时出现语法错误

转载 作者:太空宇宙 更新时间:2023-11-04 08:12:24 24 4
gpt4 key购买 nike

<分区>

我在运行以下代码时遇到问题(这是 Zed Shaw 的“艰难地学习 Python”中的练习 15):

from sys import argv

script, filename = argv

txt = open(filename)

print "Here's your file %r." % filename print txt.read()

print "Type the filename again: " file_again = raw_input("==>")

txt_again = open(file_again)

print txt_again.read()

txt.close() txt_again.close()

我尝试从终端运行它并获得以下信息:

dominics-macbook-4:MyPython Dom$ python ex15_sample.txt
File "ex15_sample.txt", line 1
This is stuff I typed into a file.
^
SyntaxError: invalid syntax

这是 ex15_sample.txt 的内容:

"This is stuff I typed into a file.
It is really cool stuff.
Lots and lots of fun to have in here."

我要用头撞墙了! (Python 2.6.1, OS X 10.6.8)

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com