I am working on a Student Enrolment app that writes student data to a .csv file which can then be read from later.
After user input has been completed I am getting an AttributeError within my “write_to_file” function.
This is the current “Student” class
class Student:
def __init__(self, studentID, name, email, password, subjectID=None, mark=None, grade=None):
self.studentID = studentID
self.name = name
self.email = email
self.password = password
self.subjectID = subjectID
self.mark = mark
self.grade = grade
This is the current “write_to_file” function
def write_to_file(self, students):
with open(self.file_name, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow([" ID ", " Name ", " Email ", " Password ", " Subjects ", " Mark ", " Grade "])
for student in students:
row = ([student.studentID, student.name, student.email, student.password, student.subjectID, student.mark, student.grade])
writer.writerow(row)
The first row of the student.data.csv file is being succesfully created with the column headers but I am being hit with the AttributeError on the line
row = ([student.studentID, student.name, student.email, student.password, student.subjectID, student.mark, student.grade])
AttributeError: type object ‘Student’ has no attribute ‘studentID’
Apologies in advance if my formatting isn’t 100%, first time poster.
Lochlan Peacock is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.