How can I call a subclass method from parent class ?
bonono at gmail.com
bonono at gmail.com
Thu Oct 20 06:00:10 EDT 2005
thanks, it works. Though I don't quite understand what super(cls,cls)
returns, and it doesn't work if I do a super(cls,cls).foo(). But
cls.__base__.foo() do the trick.
thankfully, I don't have multiple inheritance.
Jason Lai wrote:
> If you use a newstyle class, e.g. class A(object), then you can get the
> superclass with cls.__base__. You could also use super(cls,cls),
> although note that it returns a <super> object that isn't exactly the
> same thing as a class -- but good enough for just accessing attributes.
>
> Make sure to check that your superclass isn't <object>, otherwise it'll
> complain about <object> not having a foo attribute. __base__ is
> probably easier for this purpose. Also be careful with multiple
> inheritance.
>
> No such thing as __super though.
More information about the Python-list
mailing list