-
Notifications
You must be signed in to change notification settings - Fork 0
control_and_setup
CSharplie edited this page Apr 17, 2024
·
1 revision
The function control_and_setup is the only one to use in PyJeb. It use to apply controls and setup default and variables values.
Definition: control_and_setup(<configuration>, <controls>, [<variables>], [<functions>], [<to_object>])
Parameters:
Name | Mandatory | Type | Description |
---|---|---|---|
configuration | yes | Dict | A dictionary (of scalar or array or dictonnary) who contain the configuration to control and variabilize |
controls | yes | List | A list of dictionnaries who define the structure of configuration. See all about the structure in controls page |
variables | no | Dict | Custom variables accessible by configuration. See all about it in custom variable page |
functions | no | Dict | Custom parametrized variables accessible by configuration. See all about it in custom variable page |
to_object | no | Bool | Transform the output into an object. If false the output keeps dictionary format (default: false) |
Return:
Configuration controlled and setup with variables instantiated and functions evaluated.
import yaml
from pyjeb import control_and_setup
# setup control
controls = [
{ "name": "name" },
{ "name": "color", "valid_set": ["red", "green", "blue"] },
{ "name": "size.width", "type": "int" },
{ "name": "size.length", "type": "int" }
]
# configuration
configuration = {
"name": "Ford ka+",
"color": "black",
"size": {
"width": 10,
"length": 20
}
}
# control and setup
# will raise an exception because the color is not in the valid_set
configuration = control_and_setup(configuration, controls, to_object=True)
See Custom variables for more details and examples.
See Custom functions for more details and examples.