0
When I run this code (this is the current entire code, ie only 3 lines):
import pygame
class sp(pygame.sprite):
pass
I get:
Typeerror: module() takes at Most 2 Arguments (3 Given)
I would like to inherit this class to create some additional objects in it as well as perform some of the existing functions.
For example, instead of ...
mysprites = pygame.sprite.Group()
I want...
mysprites = sp.Group()
How can I do that?
Yes, but as I said, I would like to inherit this class to create some additional objects in it... how to do in this case?
– Rogério Dec
@Rogériodec The answer is clear - it is not possible to "inherit this class" because
sprite
is a module and not a class - and "inherit" only works with classes.– nosklo
Maybe you can think of another way to do what you want - you probably don’t have to inherit anything to do. Remember that python is different from languages like java where each file is a class and everything needs to be classes. In python this is simplified, you can have loose functions and use the modules at will.
– nosklo
-1 - both the author and what makes sense in Pygame is inheriting from the Sprite class - only a well-advanced use in large project will need to inherit Sprite. Groups to create something new. Already inherit from Sprite.Sprite is made for normal pygame use: the idea is that the objects to be displayed on the screen set in the user code run some boot code and keep some internal states to work well with the various types of
pygame.sprite.Group
predefined.– jsbueno
@jsbueno I am not suggesting that the OP inherits from
Group
for some reason. I’m just saying that you can only inherit from classes, and never from modules. I think you were hasty in giving -1 to the answer, which is correct. Read again– nosklo
there is nothing hasty there - the wrong thing is to give 1 less for the correct answer for "revenge" - if you had familiarity with the library or looked at the documentation, you would see that the AP confused the module with the class. You could at least put the phrase "you’ve probably confused "pygame.sprite.Sprite" with "pygame.Sprite". - Instead, it suggests an inheritance that, correct in terms of OOP, in practical terms when doing a pygame project, is meaningless for beginners. I don’t consider that answer to be correct.
– jsbueno
@good jsbueno, I was not the one who gave -1 for your answer, which in my opinion although correct does not answer the question asked by the OP, so I also did not give +1, but I do not think she deserves -1.
– nosklo
@jsbueno But that’s the way it is, so there’s the voting system - not everyone will agree here, so everyone gives the vote they think best.
– nosklo