param.parameterized.Parameters.add_parameter#
- Parameters.add_parameter(param_name: str, param_obj: Parameter)[source]#
Add a new Parameter object to this class.
This method allows dynamically adding a Parameter to the class, resulting in behavior equivalent to declaring the Parameter in the class’s source code.
- Parameters:
param_name (str) – The name of the parameter to add.
param_obj (Parameter) – The Parameter object to add.
Examples
Create a Parameterized class:
>>> import param >>> class P(param.Parameterized): ... a = param.Number() ... b = param.String() >>> p = P()
Add a new parameter to the class P via the class namespace P.param:
>>> P.param.add_parameter('c', param.Tuple(default=(1, 2, 3))) >>> print(p.c) (1, 2, 3)
Add a new parameter to the class P via the instance namespace p.param:
>>> p.param.add_parameter('d', param.Tuple(default=(3, 2, 1))) >>> p.d (3, 2, 1)