There are multiple ways of doing this, I would say the most obvious one is using a metaclass but moving your for loop 1 indentation level up will also work.
As for the existance of enums: http://docs.python.org/3.4/library/enum.html
Here's a metaclass example:
class EnumMeta(type):
def __new__(cls, name, bases, dict_):
names = dict_.get('_enum_string', '')
if names:
for i, name in enumerate(names.split()):
dict_[name] = 'foo %d' % i
return super(EnumMeta, cls).__new__(cls, name, bases, dict_)
class Node(object):
__metaclass__ = EnumMeta
_enum_string = 'state1 state2'
print 'state1', SomeMeta.state1
print 'state2', SomeMeta.state2
Or a simple version with a loop (but ugly imho, and less flexible):
class Node(object):
pass
for i, state in enumerate('state1 state2'.split()):
setattr(Node, state, i)