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

Use the filehandle f not filename

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.