> Python primo nerozlisuje, ktere z atributu jsou "promenne" a ktere metody. > Vase potreba je nicmene pofiderni a naznacuje neoptimalni navrh programu > -- jen velmi zridka je neco takoveho potreba. Neznal ale podrobnosti. >
Souhlasim se zrejme neoptimalnim navrhem programu, ale jako studijni pomucka je to dobry napad :) Nakonec mi to nedalo a napsal jsem funkci, ktera myslim dela pozadovane, viz nize. (kdyby se rozhodilo formatovani, tak je kopie na http://dpaste.com/65418/) Jirka # data class TestClass(object): def __init__(self): self.var1 = 1 self.var2 = '2' def func1(self): self.var3 = 3 def func2(self): self.var4 = '4' # utility func def get_vars(inst): res = [] for attr_name in inst.__dict__: attr = getattr(inst, attr_name) if not attr_name.startswith('_') and not callable(attr): res.append(attr_name) return res if __name__ == '__main__': x = TestClass() print get_vars(x) x.func1() print get_vars(x) x.func2() print get_vars(x)
_______________________________________________ Python mailing list [email protected] http://www.py.cz/mailman/listinfo/python
