bundle Package

bundle Package

Implement a dictionary-like class Bundle, which enables attribute-like access to its elements. So, for example, instead of

>>> bundle['key1'] = 'hello'

you can also do

>>> bundle.key1 = 'hello'

The same is true for reading access:

>>> bundle.key1
hello

Another extension is the method intersection(), which is the equivalent to the method of the set type with the same name.

Limitations

In contrast to conventional dictionaries, keys must be strings.

class bundle.__init__.Bundle(arg=None, **kwargs)

Bases: _abcoll.MutableMapping

Dictionary-like data structure (actually wraps a dictionary, and provides a dictionary-like interface), but with the following changes:

  1. Elements can also be accessed like attributes, e.g. a.b = c instead of a[‘b’] = c.
  2. Because of the above, all keys have to be strings.
  3. Added set-like methods, like “intersection”.
copy()
intersection(*others)

Return intersection of the given bundles, containing only key-value pairs that are equal in all the bundles.

bundle.__init__.intersection(*bundles)

Return intersection of the given bundles, containing only key-value pairs that are equal in all of the bundles.

To be clear: Both key AND value have to agree among all of the input bundles, otherwise a key-value pair does not appear in the output bundle.

Table Of Contents

This Page