Guest User

ps8 file to dictionary

a guest
May 5th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #the function takes a txt file and returns a library of string keys and tuple values
  2. SUBJECT_FILENAME = 'test_subject_file.txt'
  3. ##for testing I am using a short txt file with the following:
  4. ##2.00,5,9
  5. ##2.01,2,2
  6. ##2.02,1,17
  7. ##2.03,6,1
  8. ##2.04,3,2
  9. ##2.05,2,2
  10. ##2.06,2,1
  11. ##2.07,1,1
  12. ##2.08,5,5
  13. ##2.09,5,2
  14. ##2.10,6,12
  15. ##2.11,9,19
  16. ##2.12,10,4
  17. ##2.13,5,20
  18. ##2.14,8,19
  19. ##2.15,9,19
  20. ##2.16,9,20
  21. ##2.17,10,20
  22. ##2.18,6,16
  23. ##2.19,6,19
  24.  
  25. def loadSubjects(filename):
  26. #open the file and initiate library
  27. class_file = open(filename)
  28. class_library = {}
  29.  
  30. for item in class_file:
  31.  
  32. print item
  33. raw_input()
  34. #split each line of the file into a list of ['name','value','hours']
  35. element_list = item.split(',')
  36.  
  37. print element_list
  38. raw_input()
  39.  
  40. #convert value and hours into integers
  41. element_list[1] = int(element_list[1])
  42. element_list[2] = int(element_list[2])
  43.  
  44. print element_list
  45. raw_input()
  46.  
  47. #map the name to a tuple of the value and hours integers
  48. class_library[item[0]] = tuple(element_list[1:])
  49. print class_library
  50. raw_input()
  51. return class_library
Advertisement
Add Comment
Please, Sign In to add comment