I am trying to sort a list which is in a private class, i can sort it without getting private but can't in private.
First i open data and split it in main.py, and set a list call StudentDL in main.py and call it to Student.py , if I private Student.py, I can't sort the StudentDL list in main.py .
How can I sort the StudentDL list in main.py or Student.py after private Student.py?
Main.py:
from Student import Student
StudentDL = []
file = open('markdata.dat', 'r')
line = file.readline()
while line != '':
StudentRec = line.split('_')
StudentDL.append(Student(int(StudentRec[0]),str(StudentRec[1]),
float(StudentRec[2]),
float(StudentRec[3])))
line = file.readline()
file.close()
for e in StudentDL:
print (e)
for e in sorted(StudentDL, key=lambda c:c.sID):
print (e)
print('='*20)
for e in sorted(StudentDL, key=lambda c:c.n):
print (Student.overall(e))
Student.py:
class Student(object):
numStudent = 0
def __init__(self,studentID,name,cwmark,exammark):
Student.numStudent += 1
self.__sID = studentID
self.__n = name
self.__cwm = cwmark
self.__exm = exammark
self.__om = (cwmark*0.4)+(exammark*0.6)
def __str__(self):
return '%-15s%-27s%-10.2f%7.2f'%\
(self.__sID,self.__n,self.__cwm,self.__exm)
def overall(self):
return '%-15s%-27s%-12.2f%-7.2f%8.2f'%\
(self.__sID,self.__n,self.__cwm,self.__exm,self.__om)
def getoverall(self):
return float(self.__om)
markdata:
50123456_lam tai man_70.0_60.0_
50223456_li tai man_60.0_90.5_
50323456_wong tai man_34.5_30.0_
50423456_ng tai man_90.5_70.0_
50523456_lau tai man_86.0_92.4_
50623456_chui tai man_70.0_64.5_
50723456_lim tai man_64.5_60.0_
50823456_pok tai man_37.5_35.50_
50923456_kim tai man_92.4_60.0_
50023456_tsang tai man_15.0_20.0_
50999999_chan peter_100.00_80.00_