param.ParameterizedFunction#
- class param.ParameterizedFunction(*, name)[source]#
Acts like a Python function, but with arguments that are Parameters.
When a
ParameterizedFunctionis instantiated, it automatically calls its__call__method and returns the result, acting like a Python function.Features:
Declarative parameterization: Arguments are defined as
Parameterobjects, enabling type validation, bounds checking, and documentation.Dynamic updates: Changes to parameters can dynamically influence the function’s behavior.
References
See https://param.holoviz.org/user_guide/ParameterizedFunctions.html
Notes
Subclasses of
ParameterizedFunctionmust implement the__call__method, which defines the primary functionality of the function.The
instance()method can be used to obtain an object representation of the class without triggering the function’s execution.
Examples
Define a subclass of
ParameterizedFunction:>>> import param >>> class Scale(param.ParameterizedFunction): ... multiplier = param.Number(default=2, bounds=(0, 10), doc="The multiplier value.") ... ... def __call__(self, x): ... return x * self.multiplier
Instantiating the parameterized function calls it immediately:
>>> result = Scale(5) >>> result 10
Access the instance explicitly:
>>> scale3 = Scale.instance(multiplier=3) >>> scale3.multiplier 3 >>> scale3(5) 15
Customize parameters dynamically:
>>> scale3.multiplier = 4 >>> scale3(5) 20
Parameter Definitions
Methods
Attributes
param