Read from TXT file - Please Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kate s
    New Member
    • Nov 2008
    • 5

    Read from TXT file - Please Help

    I have an employee txt file. It looks like this:

    Number / Name / Qualifications /
    007 / Tim / Diploma in Business
    005 / Tom / IT project management
    006 / Marry / Business Admin
    008 / Larry / IT Support

    Ill open the text file first: text_file = open ("employee.t xt, "r")

    The user will enter the employee number and python will read first line and display name and qualifications for the given employee number.

    How do I allow the user to input the employee number and display back name and qualifications?

    Any help would be appreciated!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    You could read the data into a dictionary. The employee numbers would be the dictionary keys. If the user enters a valid employee number, the information would be displayed.

    Example:
    [code=Python]
    employeeDict = {'008': ['Larry', 'IT Support']}
    choice = raw_input('Ente r employee number')
    choice_value = dd.get(choice, None)[/code]If choice_value is not None, display the information, otherwise display a message that the employee number is not in the database.

    Comment

    Working...