Exercise 17 - copy file
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print("Copying from %s to %s" % (from_file, to_file))
# we could do these two on one line too, how?
in_file = open(from_file)
indata = in_file.read()
print("The input file is %d bytes long" % len(indata))
print("Does the output file exist? %r" % exists(to_file))
print("Ready, hit RETURN to continue, CTRL-C to abort.")
input()
out_file = open(to_file, 'w')
out_file.write(indata)
print("Alright, al done.")
out_file.close()
in_file.close()
output
D:\>python ex17.py text1.txt text2.txt
Copying from text1.txt to text2.txt
The input file is 5 bytes long
Does the output file exist? True
Ready, hit RETURN to continue, CTRL-C to abort.
Alright, al done.
2019-09-28
20:16:24
posted on 2019-09-28 16:16 petit_herisson 阅读(111) 评论(0) 收藏 举报
浙公网安备 33010602011771号