obspy.core.util.attribdict.AttribDict

class AttribDict(*args, **kwargs)[source]

Bases: MutableMapping

A class which behaves like a dictionary.

Parameters:

data (dict, optional) – Dictionary with initial keywords.

Basic Usage

You may use the following syntax to change or access data in this class.

>>> stats = AttribDict()
>>> stats.network = 'BW'
>>> stats['station'] = 'ROTZ'
>>> print(stats.get('network'))
BW
>>> print(stats['network'])
BW
>>> print(stats.station)
ROTZ
>>> x = stats.keys()
>>> x = sorted(x)
>>> print(x[0], x[1])
network station

Attributes

defaults

do_not_warn_on

readonly

warn_on_non_default_key

Public Methods

clear

copy

get

items

keys

pop

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem

as a 2-tuple; but raise KeyError if D is empty.

setdefault

update

values

Private Methods

Warning

Private methods are mainly for internal/developer use and their API might change without notice.

AttribDict._cast_type(key, value)[source]

Cast type of value to type required in _types dict.

Parameters:
  • key (str) – The key from __setattr__.

  • value – The value being set to key.

Returns:

value cast to correct type.

AttribDict._pretty_str(priorized_keys=[], min_label_length=16)[source]

Return better readable string representation of AttribDict object.

Parameters:
  • priorized_keys (list[str], optional) – Keywords of current AttribDict which will be shown before all other keywords. Those keywords must exists otherwise an exception will be raised. Defaults to empty list.

  • min_label_length (int, optional) – Minimum label length for keywords. Defaults to 16.

Returns:

String representation of current AttribDict object.

Special Methods

classmethod AttribDict.__class_getitem__()

Represent a PEP 585 generic type

E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,).

AttribDict.__contains__(key)
AttribDict.__delattr__(name)
AttribDict.__delitem__(name)[source]
AttribDict.__dir__()

Default dir() implementation.

AttribDict.__eq__(other)
AttribDict.__format__(format_spec, /)

Default object formatter.

AttribDict.__ge__(value, /)

Return self>=value.

AttribDict.__getattr__(name, default=None)[source]

Py3k hasattr() expects an AttributeError no KeyError to be raised if the attribute is not found.

AttribDict.__getattribute__(name, /)

Return getattr(self, name).

AttribDict.__getitem__(name, default=None)[source]
AttribDict.__gt__(value, /)

Return self>value.

AttribDict.__init__(*args, **kwargs)[source]

An AttribDict can be initialized in two ways. It can be given an existing dictionary as a simple argument or alternatively all keyword arguments will become (key, value) pairs.

>>> attrib_dict_1 = AttribDict({"a":1, "b":2})
>>> attrib_dict_2 = AttribDict(a=1, b=2)
>>> attrib_dict_1  
AttribDict({'a': 1, 'b': 2})
>>> assert(attrib_dict_1 == attrib_dict_2)
AttribDict.__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

AttribDict.__iter__()[source]
AttribDict.__le__(value, /)

Return self<=value.

AttribDict.__len__()[source]
AttribDict.__lt__(value, /)

Return self<value.

AttribDict.__ne__(value, /)

Return self!=value.

AttribDict.__new__(**kwargs)
AttribDict.__reduce__()

Helper for pickle.

AttribDict.__reduce_ex__(protocol, /)

Helper for pickle.

AttribDict.__repr__()[source]
AttribDict.__setattr__(key, value)
AttribDict.__setitem__(key, value)[source]
AttribDict.__sizeof__()

Size of object in memory, in bytes.

AttribDict.__str__()

Return str(self).

classmethod AttribDict.__subclasshook__(C)