-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize_csv.py
28 lines (23 loc) · 941 Bytes
/
initialize_csv.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
from os import path
from os import remove
import csv
def init_customer_csv(filename):
"""
Initializes csv by deleting filename (if exists),
setting headers, and adding mock customer info
"""
# Clear out file if it already exists
if path.exists(filename):
remove(filename)
# Set headers and data
headers = ["first_name", "last_name", "email_address", "password", "tel_number"]
data = [["Ada", "Lovelace", "[email protected]", "alovelace123", "None"],
["Grace", "Hopper", "[email protected]", "ghopper456", "None"],
["Edith", "Clarke", "[email protected]", "eclark789", "None"],
["Carol", "Shaw", "[email protected]", "cshaw123", "None"]]
# Write headers, data
with open(filename, "w") as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(headers)
csvwriter.writerows(data)
init_customer_csv("pybank_customers.csv")