param.Path#
- class param.Path(self, default=<Undefined>, *, search_paths=<Undefined>, check_exists=<Undefined>, **params)[source]#
Parameter that can be set to a string specifying the path of a file or folder.
The string should be specified in UNIX style, but it will be returned in the format of the user’s operating system. Please use the
FilenameorFoldernameParameters if you require discrimination between the two possibilities.The specified path can be absolute, or relative to either:
any of the paths specified in the
search_pathsattribute (ifsearch_pathsis notNone);any of the paths searched by
resolve_path()(ifsearch_pathsisNone).
- Parameters:
search_paths (list, default=[os.getcwd()]) – List of paths to search the path from
check_exists (boolean, default=True) – If True (default) the path must exist on instantiation and set, otherwise the path can optionally exist.
- __init__(default=None, *, search_paths=None, check_exists=True, allow_None=False, doc=None, label=None, precedence=None, instantiate=False, constant=False, readonly=False, pickle_default_value=True, per_instance=True, allow_refs=False, nested_refs=False, default_factory=None, metadata=None)[source]#
Initialize a new
Parameterobject with the specified attributes.- Parameters:
default (Any, optional) – The owning class’s value for the attribute represented by this parameter, which can be overridden in an instance. Default is
None.default_factory (callable, optional) –
A callable used to generate the attribute value. It can be provided directly (in which case it is invoked with no arguments) or wrapped in a
DefaultFactoryfor more advanced behavior (in which case it receivescls,self, andparameteras arguments). When specified,default_factorytakes precedence overdefault. The factory is invoked once theParameterizedinstance is initialized.Added in version 2.3.0.
doc (str | None, optional) – A documentation string describing the purpose of the parameter. Default is
None.label (str | None, optional) – An optional text label used when displaying this parameter, such as in a listing. If not specified, the parameter’s attribute name in the owning
Parameterizedobject is used.precedence (float | None, optional) – A numeric value, usually in the range 0.0 to 1.0, that determines the order of the parameter in a listing or user interface. A negative precedence indicates a parameter that should be hidden in such listings. Default is
None.instantiate (bool, optional) – Whether the default value of this parameter will be deepcopied when a
Parameterizedobject is instantiated (True), or if the single default value will be shared by all Parameterized instances (False, the default). For an immutableParametervalue, it is best to leaveinstantiateat the default ofFalse, so that a user can choose to change the value at theParameterizedinstance level (affecting only that instance) or at theParameterizedclass or superclass level (affecting all existing and future instances of that class or superclass). For a mutableParametervalue, the default ofFalseis also appropriate if you want all instances to share the same value state, e.g. if they are each simply referring to a single global object like a singleton. If instead eachParameterizedshould have its own independently mutable value, instantiate should be set toTrue, but note that there is then no simple way to change the value of this parameter at the class or superclass level, because each instance, once created, will then have an independently deepcopied value. Default isFalse.constant (bool, optional) – If
True, the parameter value can only be set at the class level or in aParameterizedconstructor call. The value is otherwise constant on theParameterizedinstance, once it has been constructed. Default isFalse.readonly (bool, optional) – If
True, the parameter value cannot be modified at the class or instance level. Default isFalse.pickle_default_value (bool, optional) –
Whether the default value should be pickled. Set to
Falsein rare cases, such as system-specific file paths.Deprecated since version 2.3.0.
allow_None (bool, optional) – If
True, allowsNoneas a valid parameter value. If the default value isNone, this is automatically set toTrue. Default isFalse.per_instance (bool, optional) – Whether to create a separate
Parameterobject for each instance of theParameterizedclass (True), or share the sameParameterobject across all instances (False). See alsoinstantiate, which is conceptually similar but affects the parameter value rather than the parameter object. Default isTrue.allow_refs (bool, optional) – If
True, allows linking parameter references to this parameter, meaning the value will automatically reflect the current value of the reference that is passed in. Default isFalse.nested_refs (bool, optional) – If
Trueandallow_refs=True, inspects nested objects (e.g., dictionaries, lists, slices, tuples) for references and resolves them automatically. Default isFalse.metadata (Mapping, optional) –
An arbitrary mapping, to be used to store additional metadata than cannot be declared with the other attributes. Useful for third-party libraries to extend Param. Default is
None.Added in version 2.3.0.
Examples
Define a parameter with a default value:
>>> import param >>> class MyClass(param.Parameterized): ... my_param = param.Parameter(default=10, doc="An example parameter.") >>> instance = MyClass() >>> instance.my_param 10
Use a constant parameter:
>>> class ConstantExample(param.Parameterized): ... my_param = param.Parameter(default=5, constant=True) >>> instance = ConstantExample() >>> instance.my_param = 10 # Raises an error ... TypeError: Constant parameter 'my_param' cannot be modified.
Methods
__init__([default, search_paths, ...])Initialize a new
Parameterobject with the specified attributes.deserialize(value)Given a serializable Python value, return a value that the parameter can be set to.
schema([safe, subset, mode])Generate a schema for the parameters of the
Parameterizedobject.serialize(value)Given the parameter value, return a Python value suitable for serialization.
Attributes
search_pathscheck_existsallow_Noneallow_refsconstantdefaultdefault_factorydocinstantiatelabelGet the label for this parameter.
metadatanamenested_refsownerper_instancepickle_default_valueprecedencereadonlyrxThe reactive operations namespace.
watchers