473,508 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple inheritance : waht does this error mean ?

I am using Python 2.4.3
class K(object,list):

...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list
Regards
Jitendra Nair

May 16 '06 #1
4 5597
jn***@ensim.com writes:
class K(object,list):

...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list


The class 'object' is already the base class of 'list', and of every
other basic type.

Python is saying that you need to decide what you want; inheritance
from 'object', or inheritance from something that already inherits
from 'object'.

--
\ "People come up to me and say, 'Emo, do people really come up |
`\ to you?'" -- Emo Philips |
_o__) |
Ben Finney

May 16 '06 #2
Question for you: what do you think that "class K(object,list):"
means?? What are you trying to achieve? What do you plan to do with K?
If you want it to be a subclass of list, all you have to do is "class
K(list):".

May 16 '06 #3
jn***@ensim.com wrote:
I am using Python 2.4.3
class K(object,list): ...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list


class K(object, list): pass

specifies that a method should be looked up first in object, then in list.
As list inherits from object, its method resolution order
list.__mro__ (<type 'list'>, <type 'object'>)

specifies that a method should be looked up first in list, then in object.
Python refuses to resolve the conflict for you, but you can do it manually:
class K2(list, object): pass .... K2.__mro__ (<class '__main__.K2'>, <type 'list'>, <type 'object'>)

Now K2, list, and object can agree to look for a method in K2, then list,
then object. However, you get the same effect by just inheriting from list:
class K3(list): pass .... K3.__mro__

(<class '__main__.K3'>, <type 'list'>, <type 'object'>)

Peter
May 16 '06 #4
jn***@ensim.com wrote:
I am using Python 2.4.3
class K(object,list):

...: pass
...:
------------------------------------------------------------
Traceback (most recent call last):
File "<console>", line 1, in ?
TypeError: Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases object, list


It is explained here:

http://www.python.org/download/releases/2.3/mro/

Michele Simionato

May 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2805
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
5
2166
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
22
23319
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
45
6309
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
47
3592
by: Mark | last post by:
why doesn't .NET support multiple inheritance? I think it's so silly! Cheers, Mark
14
3575
by: dl | last post by:
I have two classes, say A and B, both having a data member 'int n'; private in A, public in B. When I derive class C from both public A and public B, B::n should be visible to C while A::n...
7
3716
by: Adam Nielsen | last post by:
Hi everyone, I'm having some trouble getting the correct chain of constructors to be called when creating an object at the bottom of a hierarchy. Have a look at the code below - the inheritance...
3
2535
by: Jess | last post by:
Hello, I've been reading Effective C++ about multiple inheritance, but I still have a few questions. Can someone give me some help please? First, it is said that if virtual inheritance is...
47
3953
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7391
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7501
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5056
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.