Bases: 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:
>>> units.get('m/s')
'm/s'
>>> units['S']
's'
>>> units.OTHER
'other'
>>> units[3]
'm/(s*s)'
>>> units.xxx
Traceback (most recent call last):
...
KeyError: '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:
>>> units("M*s")
'm*s'
>>> units('xxx')
>>> 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'})
>>> units2('m')
'm'
>>> units2('meter')
'm'
Attributes
__dict__ | |
__doc__ | str(object=’‘) -> string |
__isabstractmethod__ | bool(x) -> bool |
__module__ | str(object=’‘) -> string |
__weakref__ | list of weak references to the object (if defined) |
Public Methods
get | |
items | |
iteritems | |
keys | |
values |
Special Methods
__call__ | |
__contains__ | |
__getattr__ | |
__getitem__ | |
__init__ | |
__setattr__ | |
__setitem__ | |
__str__ | >>> enum = Enum(["c", "a", "b"])
|