-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileIO.py
75 lines (42 loc) · 1.32 KB
/
fileIO.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
72
73
74
75
# # File = open("filename","r") # r, w, a, r+
# # File.close()
cities = ["Peth","London","New York", "Tokyo","Joburg"]
vacationFile = open("vacationPlaces.txt","w") #writing mode
for city in cities:
vacationFile.write(city+"\n")
# print("done")
vacationFile.close()
textFile = open("vacationPlaces.txt","r") #reading mode
FstLine = textFile.readline()
print(FstLine)
# ScndLine = textFile.readline()
# print(ScndLine)
# ThrdLine = textFile.readline()
# print(ThrdLine)
for line in textFile:
print(line,end="")
textFile.close()
# # more cities to append at the end of the file
africa = ["Harare", "Lusaka", "Gaberone","Windhoek"]
apendText = open("vacationPlaces.txt","a") # apending more text at the end of the file
for a_city in africa:
apendText.write(a_city+"\n")
apendText.close()
print("*********************************")
# # readFinal = open("vacationPlaces.txt","r") #reading the file
# # for text in readFinal:
# # print(text)
# # theWholeFile = openDis.read()
# # print(theWholeFile)
# # vacationFile.close()
file = open("vacationPlaces.txt","r")
def load(x):
# for i in x:
# print(i,end="")
out = x.read()
return out
print(load(file))
# load(file)
# with open("vacationPlaces.txt","r") as vacationFile:
# for line in vacationFile:
# print(line,end="")