What Ashvini correctly stated in his comment is as follows. This works in Python 2.
class ThingType(type):
__stuff__ = ["foo", "bar", "baz"]
@classmethod
def __iter__(cls):
return iter(cls.__stuff__)
class Thing(object):
__metaclass__ = ThingType
for thing in Thing:
print thing
And this works in Python 3:
class ThingType(type):
__stuff__ = ["foo", "bar", "baz"]
@classmethod
def __iter__(cls):
return iter(cls.__stuff__)
class Thing(object, metaclass=ThingType):
pass
for thing in Thing:
print(thing)
source
share