3.1.9.2. EnumFactory

This module provides an implementation for enumerate.

The enum factory EnumFactory() builds a enumerate from a list of names and assigns to these constants a value from 0 to N-1, where N is the number of constants:

enum1 = EnumFactory('Enum1', ('cst1', 'cst2'))

then we can get a constant’s value with:

enum1.cst1

and the number of constants using:

len(enum1)

The enum factory ExplicitEnumFactory() permits to specify the values of the constants:

enum2 = ExplicitEnumFactory('Enum2', {'cst1':1, 'cst2':3})

We can test if a value is in the enum using:

constant_value in enum2
PyDvi.Tools.EnumFactory.EnumFactory(cls_name, constant_names)[source]

Return an EnumMetaClass instance, where cls_name is the class name and constant_names is an iterable of constant’s names.

PyDvi.Tools.EnumFactory.ExplicitEnumFactory(cls_name, constant_dict)[source]

Return an ExplicitEnumMetaClass instance, where cls_name is the class name and constant_dict is a dict of constant’s names and their values.

Previous topic

3.1.9.1. DaemonSubprocess

Next topic

3.1.9.3. FuncTools

This Page