Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #the function takes a txt file and returns a library of string keys and tuple values
- SUBJECT_FILENAME = 'test_subject_file.txt'
- ##for testing I am using a short txt file with the following:
- ##2.00,5,9
- ##2.01,2,2
- ##2.02,1,17
- ##2.03,6,1
- ##2.04,3,2
- ##2.05,2,2
- ##2.06,2,1
- ##2.07,1,1
- ##2.08,5,5
- ##2.09,5,2
- ##2.10,6,12
- ##2.11,9,19
- ##2.12,10,4
- ##2.13,5,20
- ##2.14,8,19
- ##2.15,9,19
- ##2.16,9,20
- ##2.17,10,20
- ##2.18,6,16
- ##2.19,6,19
- def loadSubjects(filename):
- #open the file and initiate library
- class_file = open(filename)
- class_library = {}
- for item in class_file:
- print item
- raw_input()
- #split each line of the file into a list of ['name','value','hours']
- element_list = item.split(',')
- print element_list
- raw_input()
- #convert value and hours into integers
- element_list[1] = int(element_list[1])
- element_list[2] = int(element_list[2])
- print element_list
- raw_input()
- #map the name to a tuple of the value and hours integers
- class_library[item[0]] = tuple(element_list[1:])
- print class_library
- raw_input()
- return class_library
Advertisement
Add Comment
Please, Sign In to add comment