[Python-Dev] Error in Python Tutorial on Multiple Inheritence
Anthony Baxter
anthony at interlink.com.au
Fri Aug 13 10:15:07 CEST 2004
Steven Kah Hien Wong wrote:
> class CommonBase:
> x = 0
>
> class ChildOne(CommonBase):
> None
>
> class ChildTwo(CommonBase):
> None
>
> class ChildOneAndTwo(ChildOne, ChildTwo):
> def run(self):
> ChildOne.x = 1
> print "one =", ChildOne.x
> print "two =", ChildTwo.x
>
> ChildOneAndTwo().run()
>
> And the output was:
>
> $ python multi.py
> one = 1
> two = 0
>
> According to the documentation, I thought it should be:
>
> one = 1
> two = 1
Nope. In the code, you set a new attribute 'x' on the ChildOne
class.
Change the end of your code to
ChildOneAndTwo().run()
print "CommonBase.x", CommonBase.x
print "ChildOne.x", ChildOne.x
print "ChildTwo.x", ChildTwo.x
Anthony
More information about the Python-Dev
mailing list