overriding methods - two questions
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Fri Nov 16 12:22:51 EST 2007
Donn Ingle:
> Say I am in class Basis, doing a loop and I have a list of Child objects. I
> want to run the foo() method for each one that *has* a foo() method.
This may help (on an old Python version):
>>> class Sam: pass
...
>>> class Judy:
... def foo(self): pass
...
>>> children = [Sam(), Judy(), Sam()]
>>> for child in children: hasattr(child, "foo")
...
False
True
False
Bye,
bearophile
More information about the Python-list
mailing list