object oriented inheritance problem

M

Matthew Thorley

I am trying to inherit from ElementTree so I can add some methods. This
is the code I am trying to make work, and the following is the error I
am getting.

from elementtree import ElementTree
class AcidTree(ElementTree):
def write_string(self):
....

File "/home/hope/var/proj/acid/server/mgacparse.py", line 22, in ?
class AcidTree(ElementTree):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)


I have *no* idea what is going on here. AcidTree does not implement an
__init__. It just adds two simple methods, which aren't even being
called when then exception is thrown. The exception occurs on the class
definition line when I try to inherit from ElementTree.

I looked around, and read some stuff in the python cook book, and
everything I've seen indicates that it should just work. My only thought
is that its a 'oldstyle' vs 'newstyle' classes issue. I know that
elementtree was written to be compatible with python 1.5 so maybe it
doesn't work with the new stuff. But thats just a crazy assumption I
made up to make myself feel better.

If anyone could please exmplain what my problem *really* is I would
appreciate it greatly. Thanks very much.

-Matthew
 
F

Fredrik Lundh

Matthew said:
I am trying to inherit from ElementTree so I can add some methods. This
is the code I am trying to make work, and the following is the error I
am getting.

from elementtree import ElementTree
class AcidTree(ElementTree):
def write_string(self):
....

File "/home/hope/var/proj/acid/server/mgacparse.py", line 22, in ?
class AcidTree(ElementTree):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

I have *no* idea what is going on here.

note that you're trying to inherit from a module. the error message could
need some work...

something like

from elementtree.ElementTree import ElementTree, tostring

class AcidTree(ElementTree):
def write_string(self):
return tostring(self)

should work better.

</F>
 
M

Matthew Thorley

So is elementtree a module of modules? I didn't know you could do that.
I just assumed that from elementtree import ElementTree imported a class
from the module elementtree.

It works now. Thanks guys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top