-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile1.py
71 lines (41 loc) · 1.07 KB
/
file1.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#Andrew Sala 3B
#part 1
quote = 'Love all, trust a few, do wrong to none \n'
wf = open('quote.txt', 'w')
wf.write(quote)
wf.close()
#part 2
rf = open('quote.txt')
data = rf.read()
print(data)
rf.close()
#part 3
quote2 = 'Cowards die many times before their deaths; the valiant never taste of death but once\n'
af = open('quote.txt', 'a')
af.write(quote2)
af.close()
af = open('quote.txt')
data = af.read()
print(data)
af.close()
#part 4
quote3 = 'An overflow of good converts to bad\n'
def write2file(filename, strObj):
f = open(filename, 'w')
f.write(strObj)
f.close()
def readFile(filename):
rf = open(filename, 'r')
data = rf.read()
print(data)
rf.close()
write2file('anothaone.txt', quote3)
readFile('anothaone.txt')
#part 5
quote4 = 'Better three hours too soon than a minute too late\n'
def append2file(filename, stringObj):
ap = open(filename, 'a')
ap.write(stringObj)
ap.close()
append2file('anothaone.txt', quote4)
readFile('anothaone.txt')