Jak uzyskać listę wszystkich zmiennych w klasie, którą można iterować? Trochę jak locals (), ale dla klasy
class Example(object):
bool143 = True
bool2 = True
blah = False
foo = True
foobar2000 = False
def as_list(self)
ret = []
for field in XXX:
if getattr(self, field):
ret.append(field)
return ",".join(ret)
to powinno powrócić
>>> e = Example()
>>> e.as_list()
bool143, bool2, foo
for field in [ self.bool143, self.bool2, self.blah, self.foo, self.foobar2000 ]
? Jak to się dzieje, że nie znasz zmiennych instancji klasy?