By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,907 Members | 1,963 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,907 IT Pros & Developers. It's quick & easy.

Read from TXT file - Please Help

P: 5
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.txt, "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!
Nov 24 '08 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
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:
Expand|Select|Wrap|Line Numbers
  1. employeeDict = {'008': ['Larry', 'IT Support']}
  2. choice = raw_input('Enter employee number')
  3. choice_value = dd.get(choice, None)
If choice_value is not None, display the information, otherwise display a message that the employee number is not in the database.
Nov 24 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.