I am writing some code for a project at school. I am reading in a List that I have created as a text file with 5 attributes. This is my class object code:
class studentclass(object):
def __init__(self,firstname,lastname,classno,correct,mydate):
self.firstname = firstname
self.lastname = lastname
self.classno = classno
self.correct = correct
self.mydate = mydate
Later in the program I am using this code to read in the data, sort it and perform some calculations:
myList = [studentclass]
totalnoofrecords = 0
counter = 0
for counter in range(0,totalnoofrecords):
firstname = myList.firstname[counter]
lastname = myList.lastname[counter]
classno = myList.classno[counter]
correct = myList.correct[counter]
mydate = myList.mydate[counter]
newname = myList.firstname[counter +1]
if newname == firstname:
grade = grade + studentclass.correct(counter +1)
nummberofattempts = 2
newname2 = studentclass.firstname(counter +2)
if newname2 == firstname:
grade = grade + studentclass.correct(counter +2)
nummberofattempts = 3
mean = grade / numberofattempts
print ("num ",counter ,"=", myList[counter])
But it does not work. I get the following error message:
AttributeError: 'list' object has no attribute 'firstname'
The error message points to this line of the code:
firstname = myList.firstname[counter]
Hoping that someone call help me please. Thanks
myListis a list, not a class instance. Lists have no attributes.