I've been trying to create a program in python whereby you can access, search and input(append) the data in a CSV file. I am able to append and print the file, however I am having trouble searching the external file.
This is what my code looks like so far:
def a():
# knows to use the file (getting something that's made)
import csv
myfile = open("student01.csv", "a")
student_num = input("Enter the student number: ")
name = input("Enter student's name: ")
tutor_group = input("Enter the tutor group: ")
gender = input("Enter M or F: ")
new_record =student_num+","+name+","+tutor_group+","+gender
myfile.write(str(new_record))
myfile.write("\n")
myfile.close()
def d():
# knows to use the file (getting something that's made)
import csv
myfile = open("student01.csv", "rb")
reader = csv.reader(myfile)
for row in myfile:
print(row)
myfile.close()
def menu():
print("Welcome to Student.csv\nWhat would you like to do?")
print()
print("1. Add to the file")
print("2. Display all the data from the file")
print("3. Search for particular data")
enter = input("Enter 1, 2 or 3: ")
enter = enter.upper()
if enter == "1":
a()
elif enter == "2":
d()
else:
s()
menu()
I'm just not sure what to do now for my def s(): so that I am able to search for a student in the file by their name, number or tutor group.
Does anyone have any ideas?
Lotz