Добавить __iter__
в метакласс вместо самого класса (предполагая Python 2.x):
class Foo(object):
bar = "bar"
baz = 1
class __metaclass__(type):
def __iter__(self):
for attr in dir(Foo):
if not attr.startswith("__"):
yield attr
Для Python 3.x используйте
class MetaFoo(type):
def __iter__(self):
for attr in dir(Foo):
if not attr.startswith("__"):
yield attr
class Foo(metaclass=MetaFoo):
bar = "bar"
baz = 1