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
Public Methods
If key is not found, d is returned if given, otherwise KeyError is raised. |
|
as a 2-tuple; but raise KeyError if D is empty. |
|
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:
- 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.__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.__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.__le__(value, /)
Return self<=value.
- 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.__setattr__(key, value)
- AttribDict.__sizeof__()
Size of object in memory, in bytes.
- AttribDict.__str__()
Return str(self).
- classmethod AttribDict.__subclasshook__(C)