View difference between Paste ID: BaUZsb8L and VjKVHDy2
SHOW: | | - or go back to the newest paste.
1
# read a file
2
3
# Bruce,91923291923,bruce@email.com
4
# Alfred,3233123124,Alfred@mail.com
5
6
7
with open("file_name.csv", "r") as file_variable:
8
    f = file_variable.read() # read complete file
9
    f = file_variable.readline() # read line by line line1
10
    f = file_variable.readline() # read line by line line2 # returns None when there is nothing left to read
11
    
12
    for line in file_variable: # read all lines one by one
13
        ls = line.split(",")
14
15
16
with open("file_name.csv", "w") as file:
17
    file.write(name + "," + phone + "," + email)
18
19
20
def saveContact(name, phone, email):
21
    with open("file_name.csv", "a") as file:
22
        file.write(name + "," + phone + "," + email + "\n")
23
24
25
26