obspy.core.util.obspy_types.Enum¶
- class Enum(enums, replace={})[source]¶
Bases: builtins.object
Enumerated type (enum) implementation for Python.
Parameters: replace (dict, optional) Dictionary of keys which are replaced by values. Example
>>> from obspy.core.util import Enum >>> units = Enum(["m", "s", "m/s", "m/(s*s)", "m*s", "other"])
There are different ways to access the correct enum values:
>>> print(units.get('m/s')) m/s >>> print(units['S']) s >>> print(units.OTHER) other >>> print(units[3]) m/(s*s) >>> units.xxx Traceback (most recent call last): ... AttributeError: 'xxx'
Changing enum values will not work:
>>> units.m = 5 Traceback (most recent call last): ... NotImplementedError >>> units['m'] = 'xxx' Traceback (most recent call last): ... NotImplementedError
Calling with a value will either return the mapped enum value or None:
>>> print(units("M*s")) m*s >>> units('xxx') >>> print(units(5)) other
The following enum allows replacing certain entries:
>>> units2 = Enum(["m", "s", "m/s", "m/(s*s)", "m*s", "other"], ... replace={'meter': 'm'}) >>> print(units2('m')) m >>> print(units2('meter')) m
Attributes
__dict__ __doc__ str(object=’‘) -> str __isabstractmethod__ bool(x) -> bool __module__ str(object=’‘) -> str __weakref__ list of weak references to the object (if defined) Public Methods
get items iteritems keys values Private Methods
Warning
Private methods are mainly for internal/developer use and their API might change without notice.
_repr_pretty_ Special Methods
__call__ __contains__ __dir__ default dir() implementation __format__ default object formatter __getattr__ __getitem__ __init__ __new__ Create and return a new object. __reduce__ helper for pickle __reduce_ex__ helper for pickle __setattr__ __setitem__ __sizeof__ size of object in memory, in bytes __str__ >>> enum = Enum(["c", "a", "b"])
__subclasshook__ Abstract classes can override this to customize issubclass().