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 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
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):". 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 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
by: Mark |
last post by:
why doesn't .NET support multiple inheritance?
I think it's so silly!
Cheers,
Mark
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
| |