ecpi.common.params.tools_params module
Section author: ECLAIRs GP team
Manage spreadsheet format, tools conversion for string value
Summary
Classes:
Extract parameters value from spreadsheet to dictionary |
Class diagram:
Functions:
Automaton adding double quote in string list for each element, example |
|
Convert config parser object with section to typed dictionary |
|
Convert a dictionary where all values are a string to typed dictionary if conversion is possible with json.loads() function |
|
Convert high level dictionary (ie with different component) where value are string to typed dictionary |
|
Remove list from value and used the first element. |
|
skip_column_func for get_sheet() function |
|
Extraction a dictionary from spreadsheet file. |
Reference
- class SpreadSheetToParams(pars_file, col_key, col_value)[source]
Bases:
objectExtract parameters value from spreadsheet to dictionary
- add_double_quote_in_list_string(str_list, rm_space=False)[source]
- Automaton adding double quote in string list for each element, example
‘[[abb,e,1],[c,3.14]]’
- returns
‘[[“abb”,”e”,”1”],[“c”,”3.14”]]’
- …note::
Motivation: with double quote we can apply json.loads() function to convert string list in list.
- Parameters
str_list (str) – representation of a list as a string
rm_space (bool) – remove space character before processing
- cfgparser_to_dicttyped(cfg, section)[source]
Convert config parser object with section to typed dictionary
- Parameters
cfg (dict) – object configparser with section where values are string
section (str) – section name to convert
- Returns
typed dictionary
- dictstr_2_dicttyped(dict_str)[source]
Convert a dictionary where all values are a string to typed dictionary if conversion is possible with json.loads() function
Motivation: python library configparser gives value as string
- Parameters
dict_str (dict) – dict where values are string
- Returns
typed dictionary
- dictstr_highlevel_to_dicttyped(dict_hl)[source]
Convert high level dictionary (ie with different component) where value are string to typed dictionary
- Example of dict_hl:
- {‘CALI’: {‘array_2D_number’: ‘[[0,10],[30,40]]’,
‘array_enum’: ‘[a,b,c]’, ‘par_number’: ‘10.9’},
‘DPCO’: {‘par_path’: ‘d2’}}
- return value
- {‘CALI’: {‘array_2D_number’: [[0, 10], [30, 40]],
‘array_enum’: [‘a’, ‘b’, ‘c’], ‘par_number’: 10.9},
‘DPCO’: {‘par_path’: ‘d2’} }
- Parameters
dict_hl (dict) – high level dictionary with different sections
- Returns
typed dictionary
- remove_list_from_value(p_dict)[source]
Remove list from value and used the first element. Empty list are removed of dictionary
- Motivationget_sheet() function of pyexcel returns always a list as value, example:
{‘par_enum’: [‘i1’], ‘par_path’: [‘i2’]}
- so this function returns:
{‘par_enum’: ‘i1’, ‘par_path’: ‘i2’}
- Parameters
p_dict (dict) – dictionary with list as value.