def parse_cli_to_dictionary(input_list: List[str]) -> Dict[str, Any]: """Convert a list of strings into a dictionary with python objects as values. ```python a = parse_cli_to_dictionary(["--epochs", "5", "--test", "this", "--lr", "0.74"]) # {'epochs': 5, 'test': 'this', 'lr': 0.74} ``` Args: input_list: A list of input strings from the cli. Returns: A dictionary constructed from the `input_list`, with values converted to python objects where applicable. """ result = {} if input_list is None: return result key = "" val = "" idx = 0 while idx < len(input_list): if input_list[idx].startswith("--"): if len(key) > 0: result[key] = parse_string_to_python(val) val = "" key = input_list[idx].strip('--') else: val += input_list[idx] idx += 1 if len(key) > 0: result[key] = parse_string_to_python(val) return result
def parse_cli_to_dictionary(input_list): """ Args: input_list: A list of input strings from a cli Returns: A dictionary constructed from the input list, with values converted to python objects where applicable """ result = {} if input_list is None: return result key = "" val = "" idx = 0 while idx < len(input_list): if input_list[idx].startswith("--"): if len(key) > 0: result[key] = parse_string_to_python(val) val = "" key = input_list[idx].strip('--') else: val += input_list[idx] idx += 1 if len(key) > 0: result[key] = parse_string_to_python(val) return result
def __init__(self, system: System, est_path: str, db_path: Optional[str] = None): # Prepare db adapters sql.register_adapter(bool, int) sql.register_converter("BOOL", lambda v: bool(int(v))) sql.register_adapter(list, str) sql.register_converter("LIST[STR]", lambda v: parse_string_to_python(v)) # Prepare variables self.filename = os.path.basename(est_path) self.db_path = db_path if db_path else os.path.join(str(Path.home()), 'fastestimator_data', 'history.db') self.system = system self.db = None self.ident = (multiprocessing.current_process().pid, threading.get_ident()) self.pk = None self.stdout = None