-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchapter_08.py
More file actions
56 lines (39 loc) · 1.18 KB
/
chapter_08.py
File metadata and controls
56 lines (39 loc) · 1.18 KB
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
# ======== > Opening and Reading a file < ==========
# file = open("text1.txt", "r")
# content = file.read()
# print(content)
# file.close()
# ========= > Writing to a file < ============
# file = open("text1.txt", "w")
# file.write("\nThis is my new line.")
# file.close()
# ========= > Append Mode < ================
# file = open("text1.txt", "a")
# file.write("\nThis is my new line.")
# file.close()
# ========== > Reading line by line <==============
# file = open ("text1.txt", "r")
# content = file.read()
# print(content)
# file.close()
# for line in file:
# print(line.strip())
# file.close()
# ======== > With Statement < =============
# with open("text2.txt", "r+") as file :
# content = file.read()
# print(content)
# file.write("\n This is my new line.")
# print("file closed automatically.")
# ========= > Working with csv < ===========
import csv
# writing csv
# with open("data.csv", "w", newline="") as file:
# writer = csv.writer(file)
# writer.writerow(["Name","age"])
# writer.writerow(["Ali",20])
# writer.writerow(["sara","22"])
with open("data.csv", "r") as file1:
Content = csv.reader(file1)
for row in Content:
print(row)