0

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 store these employees information, then asking the user to search for (e.g payroll number) which then will print full details of the employee(s) with that matching payroll number.

Below is the code ive got so far.

success = False
while not(success):
    filename = input("Please enter a filename: ")
    success= True
    try:
        f = open(filename)
    except IOError:
        print("Could not open file, please try again.")
        success = False

def newEmployee(s):
     list = filename.split(" ")
     number = int(list[0])
     salary = int(list[1])
     jobtitle = list[2]
     name = list[3]
     surname = list[4]
     print(number, salary, jobtitle, name, surname)

newEmployee(filename)

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

def __str__(self):
         return format(self.payroll, "d") + format(self.salary, "d") + ' '
         + self.jobtitle + self.name
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Lardmeister
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.