A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-August/047772.html below:

[Python-Dev] Error in Python Tutorial on Multiple Inheritence

[Python-Dev] Error in Python Tutorial on Multiple Inheritence [Python-Dev] Error in Python Tutorial on Multiple InheritenceAnthony 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4