ptypy.utils.parameters.Param#
- class ptypy.utils.parameters.Param(__d__=None, **kwargs)#
Bases:
dictConvenience class: a dictionary that gives access to its keys through attributes.
Note: dictionaries stored in this class are also automatically converted to Param objects: >>> p = Param() >>> p.x = {} >>> p Param({‘x’: {}})
While dict(p) returns a dictionary, it is not recursive, so it is better in this case to use p.todict(). However, p.todict does not check for infinite recursion. So please don’t store a dictionary (or a Param) inside itself.
BE: Please note also that the recursive behavior of the update function will create new references. This will lead inconsistency if other objects refer to dicts or Params in the updated Param instance.
- __init__(__d__=None, **kwargs)#
A Dictionary that enables access to its keys as attributes. Same constructor as dict.
Methods
__init__([__d__])A Dictionary that enables access to its keys as attributes.
clear()Remove all items from the dict.
copy([depth])fromkeys(iterable[, value])Create a new dictionary with keys from iterable and values set to value.
get(key[, default])Return the value for key if key is in the dictionary, else default.
items()Return a set-like object providing a view on the dict's items.
keys()Return a set-like object providing a view on the dict's keys.
pop(k[,d])If the key is not found, return the default if given; otherwise, raise a KeyError.
popitem()Remove and return a (key, value) pair as a 2-tuple.
setdefault(key[, default])Insert key with a value of default if key is not in the dictionary.
update([__d__, in_place_depth, Convert])Update Param - almost same behavior as dict.update, except that all dictionaries are converted to Param if Convert is set to True, and update may occur in-place recursively for other Param instances that self refers to.
values()Return an object providing a view on the dict's values.
- clear()#
Remove all items from the dict.
- copy(depth=0)#
- Returns Param:
A (recursive) copy of P with depth depth
- classmethod fromkeys(iterable, value=None, /)#
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)#
Return the value for key if key is in the dictionary, else default.
- items()#
Return a set-like object providing a view on the dict’s items.
- keys()#
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.#
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()#
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)#
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update(__d__=None, in_place_depth=0, Convert=False, **kwargs)#
Update Param - almost same behavior as dict.update, except that all dictionaries are converted to Param if Convert is set to True, and update may occur in-place recursively for other Param instances that self refers to.
- Parameters:
Convert (bool) – If True, convert all dict-like values in self also to Param. WARNING This mey result in misdirected references in your environment
in_place_depth (int) – Counter for recursive in-place updates If the counter reaches zero, the Param to a key is replaced instead of updated
- values()#
Return an object providing a view on the dict’s values.