-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileI-O.py
More file actions
43 lines (33 loc) · 943 Bytes
/
fileI-O.py
File metadata and controls
43 lines (33 loc) · 943 Bytes
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
#file input output pirple
# "r" - read, "w" - write, "a" - append, "r+"" - read and write
# file = open("filename","r",)
# file.close()
cities = ["London", "Paris", "Oshawa", "Tokyo", "LA"]
cityfile = open("cityplaces", "w", )
for spots in cities:
cityfile.write(spots + "\n") #needs to be a string
cityfile.close()
cityfile = open("cityplaces", "r")
# wholefile = cityfile.read()
# print(wholefile)
# print("done")
# wholefile.close()
firstline = cityfile.readline()
print(firstline)
secondline = cityfile.readline()
print(secondline)
for line in cityfile:
print(line, end="")
cityfile.close()
finalspot = "thailand"
cityfile = open("cityplaces", "a")
cityfile.write(finalspot)
cityfile.close()
cityfile = open("cityplaces", "r")
for line in cityfile:
print(line, end="")
cityfile.close()
for i in range(5):
with open("cityplaces" + str(i), "r") as cityfile:
for line in cityfile:
print(line)