1
def print_file(name, mode='r'):
8
print "initial_file.txt: read in r mode"
9
print_file("initial_file.txt", "r")
11
print "initial_file.txt: read in r mode again"
12
print_file("initial_file.txt", "r")
14
print "initial_file.txt: read in r+ mode"
15
print_file("initial_file.txt", "r+")
17
print "initial_file.txt: read in a+ mode"
18
print_file("initial_file.txt", "a+")
21
print "initial_file.txt: read in w+ mode"
22
print_file("initial_file.txt", "w+")
25
f = file("file_1.txt", "w")
26
f.write("Write a new file, mode = 'w'\n")
29
print "file_1.txt: write test"
30
print_file("file_1.txt")
32
f = file("file_2.txt", "w")
33
f.write("Write to file multiple times\n")
34
f.write("mode = 'w'\n")
38
print "file_2.txt: read in r mode"
39
print_file("file_2.txt", "r")
41
print "file_2.txt: read in r+ mode"
42
print_file("file_2.txt", "r+")
44
print "file_2.txt: read in a+ mode"
45
print_file("file_2.txt", "a+")
47
print "file_2.txt: read in w+ mode"
48
print_file("file_2.txt", "w+")
51
f = file("file_3.txt", "w")
52
f.write("Text in w mode\n")
54
f = file("file_3.txt", "a")
55
f.write("Text appended in\n")
59
print "file_3.txt: append test"
60
print_file("file_3.txt")
62
# rwa + modes tests here
66
f = file("file_4.txt", 'w')
67
f.write("File for testing errors\n")
70
print "Writing to read only files"
72
file("file_4.txt").write("a")
78
print "Reading non-existant files"
80
file("non_existant.txt").read()
86
print "Reading form write only files"
88
file("file_4.txt",'w').read()
94
print "Reading form append only files"
96
file("file_4.txt",'a').read()