コード例 #1
0
def load_verb_dict(filename):
    """ Loads a verb dictionary from a json file """
    try:
        with open(filename, 'r') as f:
            verb_dict = json.load(f)
    except FileNotFoundError:
        print(file_not_found_msg(filename))
    else:
        return verb_dict
コード例 #2
0
def load_taxonomy(filename):
    """ Loads a taxonomy object from a pickle file """
    try:
        with open(filename, 'rb') as f:
            taxonomy = pickle.load(f)
    except FileNotFoundError:
        print(file_not_found_msg(filename))
    else:
        return taxonomy
コード例 #3
0
def load_curriculum(filename):
    """ Loads a curriculum object from a pickle file """
    try:
        with open(filename, 'rb') as f:
            curriculum = pickle.load(f)
    except FileNotFoundError:
        print(file_not_found_msg(filename))
    else:
        return curriculum
コード例 #4
0
 def set_filename_LOs(self, filename):
     """ Sets the name of the file containing the learning outcomes """
     if filename == "": return
     try:
         with open(filename, 'r') as f:
             pass
     except FileNotFoundError:
         print(file_not_found_msg(filename))
     else:
         self.filename_LOs_txt = filename
         return self.filename_LOs_txt
コード例 #5
0
 def set_num_strands_from_file(self, filename=""):
     """ Sets the number of strands from the number of blank lines in a file """
     if filename == "": # Default to self attribute if no filename provided
         filename = self.filename_LOs_txt
     tmp, self.num_of_strands = self.num_of_strands, 0
     try:
         with open (filename, 'r') as f:
             self.num_of_strands = 1 + sum(1 if line == '\n' else 0 for line in f)
     except FileNotFoundError:
         print (file_not_found_msg(filename))
         self.num_of_strands = tmp
コード例 #6
0
 def user_input_filename_LOs(self):
     """ Asks the user for the name of the input text file containing the learning outcomes """
     while True:
         filename = input("Enter the file name of the learning outcome text file: ")
         try:
             with open(filename, 'r') as f:
                 pass
         except FileNotFoundError:
             print (file_not_found_msg(filename))
         else:
             self.filename_LOs_txt = filename
             break
コード例 #7
0
 def set_num_verb_cats_from_file(self, filename=""):
     """ Sets the number of verb categories from the number of lines in a file """
     if filename == "":  # Default to self attribute if no filename provided
         filename = self.filename_verbs_txt
     tmp, self.num_of_verb_cats = self.num_of_verb_cats, 0
     try:
         with open(filename, 'r') as f:
             self.num_of_verb_cats = sum(1 for line in f)
     except FileNotFoundError:
         print(file_not_found_msg(filename))
         self.num_of_verb_cats = tmp
     else:
         return self.num_of_verb_cats
コード例 #8
0
 def user_input_filename_verbs(self):
     """ Asks user for the name of the input text file containing the verbs"""
     while True:
         filename = input(
             "Enter the file name of your verb list text file: ")
         try:
             with open(filename, 'r') as f:
                 pass
         except FileNotFoundError:
             print(file_not_found_msg(filename))
         else:
             self.filename_verbs_txt = filename  # Also returned below if needed
             break
     return filename
コード例 #9
0
 def load_LOs_from_file(self, filename=""):
     """ Creates a list of lists of learning outcome objects and loads their text from a file. Each inner list is a list of learning outcome objects pertaining to a perticular strand """
     if filename == "":
         filename = self.filename_LOs_txt
     strand_idx = 0
     try:
         with open(filename, 'r') as f:
             for line in f:
                 if line == '\n': # strands are blank line separated
                     strand_idx += 1
                     self.LOs.append([]) # Create new list for the next strand
                 else:
                     LO = LearningOutcome(line.lower().strip())
                     self.LOs[strand_idx].append(LO)
     except FileNotFoundError:
         print(file_not_found_msg(filename))