0

当我尝试使用以下代码运行模块以在 python 中打开文件时:

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()

给我以下错误:

IOError: [Errno 2] No such file or directory: 'ex15_sample.txt'
4

1 回答 1

0

可能该文件ex15_sample.txt不在当前执行目录中?您是否尝试在raw_input步骤中写入文件的完整路径,即/tmp/ex15_sample.txt

于 2013-07-19T08:17:49.883 回答