Even if the value is modify, you can display the default value with `default` method:
>>> config.option('disk.path').value.set('/')
>>> config.option('disk.usage').value.set(1.0)
>>> config.option('disk.usage').value.get()
1.0
>>> config.option('disk.usage').value.default()
668510105600.0
#### Return to the default value
If the value is modified, just `reset` it to retrieve the default value:
>>> config.option('disk.path').value.set('/')
>>> config.option('disk.path').value.get()
/
>>> config.option('disk.path').value.reset()
>>> config.option('disk.path').value.get()
None
#### The ownership of a value
Every option has an owner, that will indicate who changed the option's value last.
The default owner of every option is "default", and means that the value is the default one.
If you use a "reset" instruction to get back to the default value, the owner will get back
to "default" as well.
>>> config.option('disk.path').value.reset()
>>> config.option('disk.path').owner.isdefault()
True
>>> config.option('disk.path').owner.get()
default
>>> config.option('disk.path').value.set('/')
>>> config.option('disk.path').owner.isdefault()
False
>>> config.option('disk.path').owner.get()
user
All modified values have an owner. We can change at anytime this owner:
>>> config.option('disk.path').owner.set('itsme')
>>> config.option('disk.path').owner.get()
itsme
.. note::
This will work only if the current owner isn't "default".
This new user will be keep until anyone change the value:
>>> config.option('disk.path').value.set('/')
>>> config.option('disk.path').owner.get()
user
This username is in fact the `config` user, which is `user` by default:
>>> config.owner.get()
user
This owner will be the owner that all the options in the config will get when their value is changed.
This explains why earlier, the owner became "user" when changing the option's value.
We can change this owner:
>>> config.owner.set('itsme')
>>> config.option('disk.path').value.set('/')
>>> config.option('disk.path').owner.get()
itsme
### Get choices from a Choice option
In the previous example, it's difficult to change the second argument of the `calc_disk_usage`.
For ease the change, add a `ChoiceOption` and replace the `size_type` and `disk` option:
.. literalinclude:: ../src/api_value_choice.py
:lines: 26-31
:linenos:
We set the default value to `bytes`, if not, the default value will be None.
:download:`download the config <../src/api_value_choice.py>`
At any time, we can get all de choices avalaible for an option:
>>> config.option('disk.size_type').value.list()
('bytes', 'giga bytes')
### Value in multi option
.. FIXME undefined
For multi option, just modify a little bit the previous example.
The user can, now, set multiple path.
First of all, we have to modification in this option:
- add multi attribute to True
- the function use in validation valid a single value, so each value in the list must be validate separatly, for that we add whole attribute to False in `ParamSelfOption` object
.. literalinclude:: ../src/api_value_multi.py
:lines: 23-25
:linenos:
Secondly, the function calc_disk_usage must return a list:
.. literalinclude:: ../src/api_value_multi.py
:lines: 11-26
:linenos:
Finally `usage` option is also a multi:
.. literalinclude:: ../src/api_value_multi.py
:lines: 27-30
:linenos:
:download:`download the config <../src/api_value_multi.py>`
#### Get or set a multi value
Since the options are multi, the default value is a list: