Attributes Container#
- class AttributesContainer#
Attributes container class.
Methods:
add_keys
([number])Add number of keys.
Return the number of attributes fields.
delete_key
(key)Delete an entire key.
delete_keys
(keys)Delete entire keys.
get
(key, attrname)Return the value associated to the key attribute attrname.
get_all
(key)Iterate over attribute name and values for the key.
has_attrname
(attrname)Return True if there is a property named attrname.
names
()Return the attributes name.
new_attr
(attrname, default)Add an attribute entry.
set_attr
(key, attrname, attrvalue)Set the values for the attributes, else create them.
- card_properties()#
Return the number of attributes fields.
- Returns:
Number of attributes fields
- Return type:
- delete_key(key)#
Delete an entire key.
- Parameters:
key (
IndexT
) – Key to delete- Raises:
_NoKey – Key does not exist
Warning
This operation may invalidate keys’ index. In fact, deleting one key implies shifting all next indices. Because of this, keys should always be removed in decreasing index order:
>>> for key in sorted(keys_to_del, reverse=True): >>> attr_container.delete_key(key)
- delete_keys(keys)#
Delete entire keys.
- Parameters:
keys (
iterable
ofIndexT
) – Keys to delete- Raises:
_NoKey – Key does not exist
Note
At the oposite of
delete_key()
method, it is not necessary to sort keys. This is done internally.
- get(key, attrname)#
Return the value associated to the key attribute attrname.
- get_all(key)#
Iterate over attribute name and values for the key.
- has_attrname(attrname)#
Return True if there is a property named attrname.
- new_attr(attrname, default)#
Add an attribute entry.
- set_attr(key, attrname, attrvalue)#
Set the values for the attributes, else create them.
- Parameters:
- Raises:
_NoAttribute – There is one attribute’s name that was not added before
WrongAttributeType – Given value does not correspond to attribute’s type
_NoKey – Key does not exist