Attributes Container#

class AttributesContainer#

Attributes container class.

Methods:

add_keys([number])

Add number of keys.

card_properties()

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.

add_keys(number=1)#

Add number of keys.

Parameters:

number (int, default 1) – Number of keys to add

card_properties()#

Return the number of attributes fields.

Returns:

Number of attributes fields

Return type:

int

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 of IndexT) – 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.

Parameters:
  • key (IndexT) – Object index

  • attrname (str) – Attribute name

Returns:

Attribute value

Return type:

Any

Raises:
  • _NoAttribute – No attribute

  • _NoKey – Key does not exist

get_all(key)#

Iterate over attribute name and values for the key.

Parameters:

key (IndexT) – Object index

Yields:

str, Any – Attribute name, and all values

Raises:

_NoKey – Key does not exist

has_attrname(attrname)#

Return True if there is a property named attrname.

Parameters:

attrname (str) – Property’s name

Returns:

Is attrname in property names?

Return type:

bool

names()#

Return the attributes name.

Returns:

Attributes names

Return type:

iterable of str

new_attr(attrname, default)#

Add an attribute entry.

Parameters:
  • attrname (str) – Attribute’s name

  • default (Any) – Default keys’ attribute value

set_attr(key, attrname, attrvalue)#

Set the values for the attributes, else create them.

Parameters:
  • key (IndexT) – Object index

  • attrname (str) – Attribute’s name

  • attrvalue (Any) – Attribute’s value

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