-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex17.py
38 lines (30 loc) · 1.27 KB
/
ex17.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#This line imports a feature from the python feature set
#argv is the argument variable gives access to command line arguments
from sys import argv
#This imports a command named "exists" This returns "True"
#if a file exists, "false" if not
from os.path import exists
#This defines the argument variable
script, from_file, to_file = argv
#This displays that we are copying from the first file to the second, and gives the names
print "Copying from %s to %s" % (from_file, to_file)
#we could do these two on one line too, how?
input = open(from_file)
indata = input.read()
#This prints the number of bytes long the first file is. len must calculate the length
#, indata is defined above as reading the input file
print "The input file is %d bytes long" % len (indata)
#"exists" must calculate if the to_file exists
print "Does the output file exist? %r" %exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
#This is just asking for a return to continue
raw_input()
#This defines the variable "output" as the opened "to_file". "w" means write
output = open(to_file, 'w')
#this takes the "indata" variable and writes it into output I guess?
output.write(indata)
print "Alright, all done."
#This closes the "output" file
output.close()
#This closes the "input" file
input.close()