12347 10000 secretary James Harrison
12348 20000 secretary Jade Powell
12341 40000 consultant Adam Johnson
Hi, lets just say that the text above is a text file. I would like to open the file whose name is supplied, reads each line from the file and supplies it to the employee-creation function, storing the results returned by this function in a list.
Im getting errors such as:
Below is the code that ive got, any help?
12348 20000 secretary Jade Powell
12341 40000 consultant Adam Johnson
Hi, lets just say that the text above is a text file. I would like to open the file whose name is supplied, reads each line from the file and supplies it to the employee-creation function, storing the results returned by this function in a list.
Im getting errors such as:
Traceback (most recent call last): File "C:\Users\Ken\Desktop\Uni Work\Programming\Assignment 2\ex1.py", line 22, in <module> newEmployee(myLines) File "C:\Users\Ken\Desktop\Uni Work\Programming\Assignment 2\ex1.py", line 9, in newEmployee list = myLines.split(" ") AttributeError: 'list' object has no attribute 'split'
Below is the code that ive got, any help?
f = open("A text file", "r"); print(f.read()) print(f.readline()) myLines = f.readlines() for line in myLines: print(line) def newEmployee(s): list = myLines.split(" ") number = int(list[0]) salary = int(list[1]) jobTitle = list[2] name = list[3] surname = list[4] print(number, salary, jobTitle, name, surname) def __str__(self): return format(self.payroll, "d") + format(self.salary, "d") + ' ' \ + self.jobtitle + self.name + self.surname newEmployee(myLines) class Employee: def __init__(self, number, salary, jobTitle, name, surname): self.number = number self.salary = salary self.jobTitle = jobTitle self.name = name self.surname = surname