NamedValues

The NamedValues class associates human-friendly names to a set of numbers or bits.

class pyasn1.type.namedval.NamedValues(*args, **kwargs)

Create named values object.

The NamedValues object represents a collection of string names associated with numeric IDs. These objects are used for giving names to otherwise numerical values.

NamedValues objects are immutable and duck-type Python dict object mapping ID to name and vice-versa.

Parameters:

*args (variable number of two-element tuple) –

name: str

Value label

value: int

Numeric value

Keyword Arguments:
 
  • name (str) – Value label
  • value (int) – Numeric value

Examples

>>> nv = NamedValues('a', 'b', ('c', 0), d=1)
>>> nv
>>> {'c': 0, 'd': 1, 'a': 2, 'b': 3}
>>> nv[0]
'c'
>>> nv['a']
2