def save_params_to_file(): """ Save evolutionary parameters in a parameters.txt file. Automatically parse function and class names. :return: Nothing. """ # Generate file path and name. filename = path.join(params['FILE_PATH'], "parameters.txt") savefile = open(filename, 'w') # Justify whitespaces for pretty printing/saving. col_width = max(len(param) for param in params.keys()) for param in sorted(params.keys()): savefile.write(str(param) + ": ") spaces = [" " for _ in range(col_width - len(param))] if isinstance(params[param], types.FunctionType): # Object is a function, save function name. savefile.write("".join(spaces) + str(params[param].__name__) + "\n") elif hasattr(params[param], '__call__'): # Object is a class instance, save name of class instance. savefile.write("".join(spaces) + str(params[param].__class__.__name__) + "\n") else: # Write object as normal. savefile.write("".join(spaces) + str(params[param]) + "\n") savefile.close()
def save_params(): """ Save evolutionary parameters :return: Nothing """ filename = params['FILE_PATH'] + str(params['TIME_STAMP']) + \ "/parameters.txt" savefile = open(filename, 'w') col_width = max(len(param) for param in params.keys()) for param in sorted(params.keys()): savefile.write(str(param) + ": ") spaces = [" " for _ in range(col_width - len(param))] savefile.write("".join(spaces) + str(params[param]) + "\n") savefile.close()
def save_params_to_file(): """ Save evolutionary parameters in a parameters.txt file. :return: Nothing. """ # Generate file path and name. filename = path.join(params['FILE_PATH'], "parameters.txt") savefile = open(filename, 'w') # Justify whitespaces for pretty printing/saving. col_width = max(len(param) for param in params.keys()) for param in sorted(params.keys()): # Create whitespace buffer for pretty printing/saving. spaces = [" " for _ in range(col_width - len(param))] savefile.write( str(param) + ": " + "".join(spaces) + str(params[param]) + "\n") savefile.close()
def save_params_to_file(): """ Save evolutionary parameters in a parameters.txt file. :return: Nothing. """ # Generate file path and name. filename = path.join(params['FILE_PATH'], "parameters.txt") savefile = open(filename, 'w') # Justify whitespaces for pretty printing/saving. col_width = max(len(param) for param in params.keys()) for param in sorted(params.keys()): # Create whitespace buffer for pretty printing/saving. spaces = [" " for _ in range(col_width - len(param))] savefile.write(str(param) + ": " + "".join(spaces) + str(params[param]) + "\n") savefile.close()