Я пишу свой первый код для копирования из одного файла в другой, но получаю ошибку как IOError: [Errno 2] Нет такого файла или каталога :.IOError: [Errno 2] Нет такого файла или каталога: From_file
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()
Я не знаю, Python, но с одной стороны, вы используете to_file (без кавычек), чтобы увидеть, если он существует, а затем следующий вы имеете out_file = открыт ('to_file', 'w'), чтобы попытаться открыть его. Должна ли она быть буквальной строкой или вы можете удалить цитаты? – Andrew
Я удалил кавычки, но все равно получаю ту же ошибку. –