From How can I represent an 'Enum' in Python?
The way I'd go about it is as follows. Just define the typical enumeration using args and then put any of your special parameters in the keyword arguments.
def enum(*args, **kwargs):
enums = dict(zip(args, range(len(args))), **kwargs)
return type('Enum', (), enums)
test = enum('a','b','c',first = 1, second = 2)
print test.a
print test.b
print test.c
print test.first
print test.second
Yields:
0
1
2
1
2
Also, this will use 0 based indexing. If you want a base of 1, as in your example, use
range(1,len(args)+1))
instead of
range(len(args))
To me, it seems like quite a hassle if you have to skip values (like four) and have specially assigned values (like first) thrown in randomly. In that case, I don't think you could use this solution (or something like it). Instead, you'd probably have to find any specially assigned strings and give those values, which is going to be a lot less graceful.