Inheritance doesn't work

Z

zefciu

I have a problem with inheritance under python. The class definition is
longer, but the troublesome thing is:

from PIL import Image
class MandelbrotImage (Image):
pass

I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "mandelimage.py", line 3, in ?
class MandelImage (Image):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)


I am using python 2.4 from the Debian (Sid) packages.

Is it a bug, or am I doing something wrong?
zefciu

--
-----BEGIN zefciu's GEEK CODE BLOCK-----
Version: 3.12
GS d-(+) s+++:-- a-- C++ UL P- L++(+++) E--- W+ N++ o?
K? w-- M- V? PS-(--) PE++(+) Y PGP+ t 5 X R tv- b++
DI D- G e>+++ h!>-- y? UF+
------END zefciu's GEEK CODE BLOCK------
 
R

Robert Kern

zefciu said:
I have a problem with inheritance under python. The class definition is
longer, but the troublesome thing is:

from PIL import Image
class MandelbrotImage (Image):
pass

I am getting the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "mandelimage.py", line 3, in ?
class MandelImage (Image):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)


I am using python 2.4 from the Debian (Sid) packages.

Is it a bug, or am I doing something wrong?

You're doing something wrong. PIL.Image is a module, not a class.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
F

Fredrik Lundh

zefciu said:
I have a problem with inheritance under python. The class definition is
longer, but the troublesome thing is:

from PIL import Image

that's a module, not a class.
class MandelbrotImage (Image):
pass

PIL's Image class isn't designed to be inherited from. to create new
images, use the Image.new() factory.

</F>
 
F

Fredrik Lundh

John said:
How do you get that error with that code?

$ python
.... pass
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

</F>
 
J

J. Clifford Dyer

Fredrik said:
$ python

.... pass
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)

</F>

Sure, but I think the question was more about how code that references
"MandelbrotImage could yield a stack that references MandelImage.
 
J

John Salerno

J. Clifford Dyer said:
Sure, but I think the question was more about how code that references
"MandelbrotImage could yield a stack that references MandelImage.

Yeah, I guess I could have been more specific. :)
 
F

Fredrik Lundh

J. Clifford Dyer said:
Sure, but I think the question was more about how code that references
"MandelbrotImage could yield a stack that references MandelImage.

well, it's been obvious for quite some time that we've now reached a
point in Python's quest for world domination where newbies start
tinkering with Python before they learn how to cut and paste text, so
I wasn't really expecting anyone to be surprised by a trivial typo.

</F>
 
J

John Salerno

Fredrik said:
well, it's been obvious for quite some time that we've now reached a
point in Python's quest for world domination where newbies start
tinkering with Python before they learn how to cut and paste text, so
I wasn't really expecting anyone to be surprised by a trivial typo.

</F>

Well, I can't say I was surprised, but my main (subtle, understated,
sneaky) point was how do you expect anyone to help you when you aren't
even giving us the proper information that produces the error?
 
F

Fredrik Lundh

John said:
Well, I can't say I was surprised, but my main (subtle, understated,
sneaky) point was how do you expect anyone to help you when you aren't
even giving us the proper information that produces the error?

I've stopped trying to make that point; I just apply a basic error correction
algorithm to the posted code, and try to make sense of the result. sometimes
it misfires (e.g. if there are multiple errors in the code), but it usually gets me
pretty close to the actual issue.

</F>
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top