4.4. foundations.dataStructures

dataStructures.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines Foundations package data structures objects.

Others:

4.4.1. Module Attributes

foundations.dataStructures.LOGGER

4.4.2. Classes

class foundations.dataStructures.NestedAttribute[source]

Bases: object

Defines an helper object providing methods to manipulate nested attributes.

Usage:

>>> nest = NestedAttribute()
>>> nest.my.nested.attribute = "Value"
>>> nest.my.nested.attribute
Value
>>> nest.another.very.deeply.nested.attribute = 64
>>> nest.another.very.deeply.nested.attribute
64
class foundations.dataStructures.Structure(*args, **kwargs)[source]

Bases: dict

Defines an object similar to C/C++ structured type.

Usage:

>>> person = Structure(firstName="Doe", lastName="John", gender="male")
>>> person.firstName
'Doe'
>>> person.keys()
['gender', 'firstName', 'lastName']
>>> person["gender"]
'male'
>>> del(person["gender"])
>>> person["gender"]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
KeyError: 'gender'
>>> person.gender
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Structure' object has no attribute 'gender'

Initializes the class.

Parameters:
  • *args (*) – Arguments.
  • **kwargs (dict) – Key / Value pairs.
update(*args, **kwargs)[source]

Reimplements the Dict.update() method.

Parameters:
  • *args (*) – Arguments.
  • **kwargs (**) – Keywords arguments.
class foundations.dataStructures.OrderedStructure(*args, **kwargs)[source]

Bases: collections.OrderedDict

Defines an object similar to C/C++ structured type.
Contrary to the Structure since this class inherits from collections.OrderedDict, its content is ordered.

Usage:

>>> people = OrderedStructure([("personA", "John"), ("personB", "Jane"), ("personC", "Luke")])
>>> people
OrderedStructure([('personA', 'John'), ('personB', 'Jane'), ('personC', 'Luke')])
>>> people.keys()
['personA', 'personB', 'personC']
>>> people.personA
'John'
>>> del(people["personA"])
>>> people["personA"]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
KeyError: 'personA'
>>> people.personA
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'OrderedStructure' object has no attribute 'personA'
>>> people.personB = "Kate"
>>> people["personB"]
'Kate'
>>> people.personB
'Kate'

Initializes the class.

Parameters:
  • *args (*) – Arguments.
  • **kwargs (dict) – Key / Value pairs.
class foundations.dataStructures.Lookup[source]

Bases: dict

Extends dict type to provide a lookup by value(s).

Usage:

>>> person = Lookup(firstName="Doe", lastName="John", gender="male")
>>> person.getFirstKeyFromValue("Doe")
'firstName'
>>> persons = foundations.dataStructures.Lookup(John="Doe", Jane="Doe", Luke="Skywalker")
>>> persons.getKeysFromValue("Doe")
['Jane', 'John']
getFirstKeyFromValue(value)[source]

Gets the first key from given value.

Parameters:value (object) – Value.
Returns:Key.
Return type:object
getKeysFromValue(value)[source]

Gets the keys from given value.

Parameters:value (object) – Value.
Returns:Keys.
Return type:object