def parse_files(self): # Set to None to avoid "referenced before assigned" complaint input_choice = None # Get all boards from directory boards = glob.glob('module1/boards/*.txt') # Present different boards to the user while True: Printer.print_content('Available boards: ') Printer.print_border_middle() # Print list of boards idx = 0 for b in boards: Printer.print_content('[' + str(idx) + ']: ' + b, align='left') idx += 1 Printer.print_border_bottom() # Get the user input input_choice = raw_input('[0-' + str(len(boards) - 1) + ']: ') Printer.print_newline() # Validate input try: input_choice = int(input_choice) if input_choice < 0 or input_choice >= len(boards): raise AssertionError('') break except (AssertionError, ValueError): Printer.print_border_top() Printer.print_content('Invalid input, try again') Printer.print_border_middle() # Parse the file the user chose self.parse_file(str(boards[input_choice]))
def parse_files(self): # Set to None to avoid "referenced before assigned" complaint input_choice_graph = None input_choice_k = None # Get all boards from directory graphs = glob.glob('module2/graphs/*.txt') # Present different graphs to the user while True: Printer.print_content('Available graphs: ') Printer.print_border_middle() # Print list of boards idx = 0 for b in graphs: Printer.print_content('[' + str(idx) + ']: ' + b, align='left') idx += 1 Printer.print_border_bottom() # Get the user input input_choice_graph = raw_input('[0-' + str(len(graphs) - 1) + ']: ') Printer.print_newline() # Validate input try: input_choice_graph = int(input_choice_graph) if input_choice_graph < 0 or input_choice_graph >= len(graphs): raise AssertionError('') break except (AssertionError, ValueError): Printer.print_border_top() Printer.print_content('Invalid input, try again') Printer.print_border_middle() # Get suggested K value for this graph graph_suggested_k = None graph_suggested_k_temp = graphs[input_choice_graph].split('.')[0].split('-')[-1] if 'k' in graph_suggested_k_temp: graph_suggested_k = int(graph_suggested_k_temp.replace('k', '')) # Get the K value Printer.print_border_top() while True: if graph_suggested_k is not None: Printer.print_content('Set K value for this graph, suggested value is ' + str(graph_suggested_k)) else: Printer.print_content('Set K value for this graph') Printer.print_border_bottom() # Get the user input input_choice_k = raw_input('[4-9]: ') Printer.print_newline() # Validate input try: input_choice_k = int(input_choice_k) if input_choice_k < 4 or input_choice_k > 9: raise AssertionError('') break except (AssertionError, ValueError): Printer.print_border_top() Printer.print_content('Invalid input, try again') Printer.print_border_middle() # Parse the file the user chose self.parse_file(str(graphs[input_choice_graph]), input_choice_k)