I have to create a class of Persons that will hold information about their name,age,NI number.These details are read from a file that would look like :
55512 Bart Simpson 45
45622 John Smith 58
46231 Alicia Sands 27
My duty is to read each line from this file and supply it to the Person-creation function and store the result in a list.I've create the class and read all the line but I don't know how to store the ouput in list after the objects are created?So far my code is:
class Persons:
def __init__(self,ni_number,name,age):
self.__ni_number=ni_number
self.__name=name
self.__age=age
inFile = input("Specify input file: ")
f=open(inFile)
for line in f.readlines():
pers=Persons(line[0],line[1],line[-1])