# import Standard Library import csv # functions def allData(): with open(csvFileName) as file: # no mode attr ASSUMES 'r' csv_reader = csv.reader(file, delimiter=',') for row in csv_reader: rows.append(row) # append each row from the reader to the List (in memory) print("Data in CSV File") print("================") headerline = rows[0] # row 1 from the csv file index 0 in the list datalines = rows[1:] # row 2 from the csv file index 1 thru end in the list print(headerline) print(datalines) rows = [] # open file as an object csvFileName = 'my_pyhon_files/myContacts.csv' with open(csvFileName) as file: # no mode attr ASSUMES 'r' csv_reader = csv.reader(file, delimiter=',') for row in csv_reader: rows.append(row) # append each row from the reader to the List (in memory) print("Data in CSV File") print("================") headerline = rows[0] # row 1 from the csv file index 0 in the list datalines = rows[1:] # row 2 from the csv file index 1 thru end in the list print(headerline) print(datalines) # Add a new row of data to the csv file print() print("New Entry Form") print("==============") newName = input("Enter a new contact name" ) newAge = input("Enter contact age: ") from datetime import datetime currentTimeStamp = datetime.now() # write the row to the csv file USING append mode with open(csvFileName, 'a', newline='') as file: myfieldnames = ['Name','Age','DateTimeEntered'] mywriter = csv.DictWriter(file, myfieldnames) mywriter.writerow({'Name': newName, 'Age': newAge, 'DateTimeEntered': currentTimeStamp}) # call read rows function allData()