我正在编写我的第一个代码,从一个文件复制到另一个文件,但收到错误为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()
答案 0 :(得分:2)
将out_file = open ('to_file','w')
更改为out_file = open (to_file,'w')
即删除引号