469,290 Members | 1,866 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,290 developers. It's quick & easy.

Problems with subclassing

Hello,

I have the following problem. I want to subclass from the pygame class
Surface, but I can't get it working:

class sprite(Surface):
def __init__(self, image_array, palette):
"some code here"

when I want to create a instance with:

gfx.sprite(arrayi, palette)
I get the following error message:
TypeError: argument 1 must be sequence of length 2, not 100

It seems that the constructor of Surface is not overrided by the one in
sprite, but why?

Jul 18 '05 #1
3 1459
Alexander Stante <al*********@yahoo.de> wrote:
I have the following problem. I want to subclass from the pygame class
Surface, but I can't get it working:

class sprite(Surface):
def __init__(self, image_array, palette):
"some code here"

when I want to create a instance with:

gfx.sprite(arrayi, palette)
I get the following error message:
TypeError: argument 1 must be sequence of length 2, not 100

It seems that the constructor of Surface is not overrided by the one in
sprite, but why?


It's possible (I'm just guessing) that the problem comes with respect to
__new__ rather than __init__ ...?
Alex
Jul 18 '05 #2
Alexander Stante wrote:
I have the following problem. I want to subclass from the pygame class
Surface, but I can't get it working:

class sprite(Surface):
def __init__(self, image_array, palette):
"some code here"

when I want to create a instance with:

gfx.sprite(arrayi, palette)
I get the following error message:
TypeError: argument 1 must be sequence of length 2, not 100

It seems that the constructor of Surface is not overrided by the one in
sprite, but why?


I think you want to override __new__, not __init__, if if could be
working at all that is. GvR wrote a lengthy introduction to this (among
other things) when Py 2.2 was released: google for "descriptor" and it
should end up somewhere.

It's also possible that Surface is not a viable baseclass at all. You
may want to consult the Pygame mailing list about that.

yours,
Gerrit.

--
Weather in Twenthe, Netherlands 13/09 08:25:
14.0°C Broken clouds mostly cloudy wind 4.5 m/s S (57 m above NAP)
--
Gerrit Holl - 2nd year student of Applied Physics, Twente University, NL.
Experiences with Asperger's Syndrome:
EN http://topjaklont.student.utwente.nl/english/
NL http://topjaklont.student.utwente.nl/
Jul 18 '05 #3
Alexander Stante wrote:
Hello,

I have the following problem. I want to subclass from the pygame class
Surface, but I can't get it working:

class sprite(Surface):
def __init__(self, image_array, palette):
"some code here"

when I want to create a instance with:

gfx.sprite(arrayi, palette)
I get the following error message:
TypeError: argument 1 must be sequence of length 2, not 100

It seems that the constructor of Surface is not overrided by the one in
sprite, but why?


Try manually specifying the subclassed constructor within your new
constructor. For example:

class sprite(Surface):
def __init__(self, image_array, palette):
Surface.__init__(self, someargs)

Then, ensure you are instantiating the subclass correctly.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by WhiteRavenEye | last post: by
4 posts views Thread by GrelEns | last post: by
2 posts views Thread by David Vaughan | last post: by
13 posts views Thread by John Perks and Sarah Mount | last post: by
11 posts views Thread by Brent | last post: by
5 posts views Thread by Mike Krell | last post: by
16 posts views Thread by manatlan | last post: by
5 posts views Thread by Ray | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.