Re: How can I call a subclass method from parent class ?

2005-10-20 Thread Steve Holden
[EMAIL PROTECTED] wrote: 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

Re: How can I call a subclass method from parent class ?

2005-10-20 Thread [EMAIL PROTECTED]
Thanks for the explanation but some how my code fail and since I don't need multiple inheritance for the moment, I would settle for the not so clean version. The documentation of super is not very clear to me too. As seen in my code, I am using classmethod which may cause some problem. Steve

Re: How can I call a subclass method from parent class ?

2005-10-20 Thread Jason Lai
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

Re: How can I call a subclass method from parent class ?

2005-10-20 Thread [EMAIL PROTECTED]
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

How can I call a subclass method from parent class ?

2005-10-19 Thread [EMAIL PROTECTED]
Hi, Suppose my class definition is like this : class A: name = A @classmethod def foo(cls): cls.__super.foo() cls.bar() @classmethod def bar(cls): print cls.name class B(A): name = B class C(B): name = C What I want is C.foo() prints