How to inherit a pygame class?

427 views python

When I run this code (this is the current entire code, ie, just 3 line):

import pygame
class sp (pygame.sprite):

I get

TypeError: module() takes at most 2 arguments (3 given)

I would like inherit this class to create some additional objects to it, as well as perform some of the already existing functions.

Ex: rather than...

mysprites = pygame.sprite.Group ()

I want...

mysprites = sp.Group ()

How can I do this?

answered question

When you subclass sprite are you overriding the __init__ method? If so can you show that code?

@101, I have now put the entire code, ie, just 3 lines...

If you're not overriding __init__ then the error is likely coming from wherever you instantiate sp.

1 Answer


I would just use import aliasing for what you want.

import pygame.sprite as sp
mysprites = sp.Group()

posted this

Have an answer?


Please login first before posting an answer.