Optional parameters
By providing a default value via the default
keyword upon parameter instantiation this parameter will be optional and may be missing from the configuration (using its default value).
class Setup(Configurable):
some_level = Integer('level', default=1)
s = Setup()
s.some_level # 1
s = Setup(ConfigFactory.from_dict({'level': 2}))
s.some_level # 2
You can also set the optional=True
if you need explicit information about whether a parameter was specified or not (in case None
is an option). Using default
will result in the default value and when dealing with the parameter you can't tell if this value was specified or not. Using the separate optional
flag provides a mechanism for that. Setting default
to something else than None
will automatically set optional
to True
.
Edited by Dominik Vilsmeier