Instanciate an option
Option
Parameter |
Comments |
|---|---|
name |
The |
doc |
The |
multi |
There are cases where it can be interesting to have a list of values rather than just one. |
default |
For each option, we can defined a default value. This value will be the value of this option until user customize it. This default value is store directly in the option. So we can, at any moment we can go back to the default value. The default value can be a Calculation. |
default_multi |
A second default value is available for multi option, This The default_multi value can be a Calculation. |
validators |
A list of Validator. |
warnings_only |
Only emit warnings if not type validation is invalid. |
properties |
A list of Properties (inside a frozenset(). |
Examples
Let’s try a simple option:
>>> from tiramisu import StrOption
>>> StrOption('welcome',
... 'Welcome message to the user login')
Add a default value:
>>> from tiramisu import StrOption
>>> StrOption('welcome',
... 'Welcome message to the user login',
... 'Hey guys, welcome here!')
Or a calculated default value:
>>> from tiramisu import StrOption, Calculation
>>> def get_value():
... return 'Hey guys, welcome here'
>>> StrOption('welcome',
... 'Welcome message to the user login',
... Calculation(get_value))
A multi option. In this case, the default value has to be a list:
>>> from tiramisu import StrOption
>>> StrOption('shopping_list',
... 'The shopping list',
... ['1 kilogram of carrots', 'leeks', '1 kilogram of potatos'],
... multi=True)
The option could be a list of list, which is could submulti:
>>> from tiramisu import StrOption, submulti
>>> StrOption('shopping_list',
... 'The shopping list',
... [['1 kilogram of carrots', 'leeks', '1 kilogram of potatos'],
... ['milk', 'eggs']],
... multi=submulti)
The default value can be a Calculation. For a multi, the function have to return a list or have to be in a list:
>>> from tiramisu import StrOption, Calculation
>>> def get_values():
... return ['1 kilogram of carrots', 'leeks', '1 kilogram of potatos']
>>> StrOption('shopping_list',
... 'The shopping list',
... Calculation(get_values),
... multi=True)
or
>>> from tiramisu import StrOption, Calculation
>>> def get_a_value():
... return 'leeks'
>>> StrOption('shopping_list',
... 'The shopping list',
... ['1 kilogram of carrots', Calculation(get_a_value), '1 kilogram of potatos'],
... multi=True)
Add a default_multi:
>>> from tiramisu import StrOption, submulti
>>> StrOption('shopping_list',
... 'The shopping list',
... ['1 kilogram of carrots', 'leeks', '1 kilogram of potatos'],
... default_multi='some vegetables',
... multi=True)
>>> StrOption('shopping_list',
... 'The shopping list',
... [['1 kilogram of carrots', 'leeks', '1 kilogram of potatos'],
... ['milk', 'eggs']],
... default_multi=['some', 'vegetables'],
... multi=submulti)
Or calculated default_multi:
>>> from tiramisu import StrOption
>>> def get_a_value():
... return 'some vegetables'
>>> StrOption('shopping_list',
... 'The shopping list',
... ['1 kilogram of carrots', 'leeks', '1 kilogram of potatos'],
... default_multi=Calculation(get_a_value),
... multi=True)