IOError:[Errno 2]没有这样的文件或目录:From_file

时间:2014-09-05 14:38:20

标签: python-2.7

我正在编写我的第一个代码,从一个文件复制到另一个文件,但收到错误为IOError:[Errno 2]没有这样的文件或目录:

Please help me in resolving this error.I would really appreciate your help.


from sys import argv
from os.path import exists
#unmask the argument
script, from_file, to_file = argv

print "Copying file from %s to %s" %(from_file, to_file)
raw_input()

# open the file

f = open(from_file)
# read the file in a object
infile = f.read()

print "Source file is %d bytes long" %len(infile)
print "Does the output file exist ? %r " %exists(to_file)
print "Read, hit RETURN to continue, CTRL-C to abort."

raw_input()
out_file = open ('to_file','w')
out_file.write(infile)

print "Closing both the files"
f.close()
out_file.close()

1 个答案:

答案 0 :(得分:2)

out_file = open ('to_file','w')更改为out_file = open (to_file,'w')即删除引号