tlpipe.kiyopy.parse_ini.parse¶
-
tlpipe.kiyopy.parse_ini.
parse
(ini_data, params, return_undeclared=False, prefix='', feedback=2, type_check=False, checking=-1)[source]¶ Parses a python file or dictionary to get parameters.
This function accepts a filename and a dictionary of keys and pre typed values. It returns a dictionary of the same keys with values read from file. It optionally performs type checking.
Parameters: - ini_data (string) – A string containing a python file name, or a dictionary. The file must contain a script (not function) that defines parameter values in the local namespace. Alternately, if ini is a dictionary, then parameters are read from the dictionary. Variables must have names and types corresponding to the params dictionary argument.
- params (dict) – A dictionary of keys and corresponding to variable names to be read from file and values corresponding to defaults if the corresponding variable is not found in the file.
- return_undeclared (boolean) – Whether to return a second dictionary of with variables found in the parameter file but not in the in params argument. Default False.
- prefix (string) – A prefix added to parameter names (defined in the keys of params) when read from the input file or dictionary. The prefix is not added to the returned output dictionary. Default ‘’.
- feedback (integer) – Desired feedback level, controlling what to print to the standard out. Value can be 1 to 10, default 2.
- type_check (boolean) – Whether to raise an exception if the recived value for a parameter is a different type than the default value. Default False.
- (deprecated, use feedback and typecheck) (checking) –
Perform various checks:
- 1’s digit: perform type checking on the values in the file and in passed params:
- 0 not at all
- 2 print warning (default)
- 3 (or greater) raise an Exception
- 10s digit: parameter feedback:
- 0 none
- 2 print message when parameters remain default value (default)
- 3 print all parameters and whether they’ve defaulted
- 1’s digit: perform type checking on the values in the file and in passed params:
Returns: - out_params (dict) – A dictionary with the same keys as argument params but with values read from file.
- undeclared (dict, optional) – A dictionary that holds any key found in the file but not in params. Returned if return_undeclared = True.