Skip to content
jbvsmo edited this page Dec 30, 2012 · 1 revision

This function should be used to create simple enumerations. Although it supports all the features of subclassing, it is hard for the user to pass the values to it.

make(name, keys, order=None, methods=None, common_attr=None, doc=None, extra=None, **kw)

Arguments:

  • name: The name of the resulting class.
  • keys: All the instances this class will have. It may be a list or a dictionary with attributes for each instance. E.g.:
['inst1', 'inst2', 'inst3']
{'inst1': {'a': 1}, 'inst2': {'a': 2}}

Also, the instances may be two item tuples with (value, name)

[(0, 'inst1'), (2, 'inst2'), (4, 'inst3')]
{(0, 'inst1'): {'a': 1}, (2, 'inst2'): {'a': 2}}
  • order: When keys is a dictionary and the numbers are not specified, this argument can be used with the elements in the right order a function to sort the keys appropriately.
make(..., order=['inst1', 'inst2'])
make(..., order=sorted)
  • methods: Functions to be added to the class that will become instance methods.
  • common_attr: Attributes that have the same initial value to be added to all instances.
  • doc: Text to document class
  • extra: Other attributes to be added to the class. Useful when a name is taken by an argument.
  • kw: Other attributes to be added to the class.