parsing¶
This module is for parsing and file handling.
-
parsing.get_cfg()¶ Retrieve the config by importing it as a module at runtime.
This should usually be called at the top of the relevant files. Depending on the current working directory, it will magically adjust the path to the config:
cwd == 'docs:': pth = '../'triggers for compilation of documentation with Sphinx.cwd == 'simulation': pth = 'bundle'triggers for config fetching insimulate.py.
If these checks fail, path is set to the current working directory, i.e.
'./'.
-
parsing.parse_val(s)¶ Regex-parse variables and attribute of a val-file (simulation stats)
- Parameters
s (str) – The val file string.
- Returns
The parsed data.
- Return type
dict
-
parsing.formula(f, **kwargs) → Union[int, float]¶ Evaluate a function in a string format by variable substitution.
- Parameters
f (str) – Function with 0 or more placeholders (
speed,size,energy, etc.) that are substituted dynamically.kwargs (int or float, optional) – The keys are the name of the placeholder, values are the replacements.
- Returns
The evaluated value after substitution.
- Return type
int or float
-
parsing.prob(value) → bool¶ Probability evaluation.
- Parameters
value (float) – The probability.
- Returns
Result of the evaluation.
- Return type
bool