I'm learning from a book by Eric Mattis. I noticed that at one point, when I change the name of the method, I get an error.
Here is an example (I removed everything unnecessary so that it does not distract):
# Importing the Group class
from pygame.sprite import Group
# create an instance of the Group class
something = group()
# main loop
while True:
something.update()
# Another class description file and its method
class Some_Class(Sprite):
def __init__(self):
super().__init__()
def update(self):
something is happening
Not a word was said about this in the book, and at first I thought that the name update
was chosen for ease of writing, because it is clear that something is being updated here and there is no need to write another name. I used to change the names of the methods at my own discretion in order to better understand what is happening here, for example, not just def update()
, but def screen_update()
or def position_update()
But this time I ran into an error and tried to figure out what was wrong for a long time, until I finally realized that it was impossible to change the name update
to something else.
Do I understand correctly that in this case this is not just a random name for the method, but some reserved name in pygame
for Group()
objects?
And what you need to remember is as a rule:
if I import from pygame.sprite import Group
and I create an instance of the Group()
class and then access methods based on that class, then I have to use only the method in the main loop update()
?
I just want to understand why this is so and not otherwise...
If this is a built-in method, then why do I create a def update()
method in the class file, because here I choose the name myself? What's the point? Or do I just refer to this method and say what it will do?
And if I create a simple instance of a class without inheritance, then I can choose arbitrary names for methods, for example:
# Import class some_class
from some_class import Some_class
# create an instance of the class Some_class
some_class = Some_class()
# main loop
while True:
some_class.some_method()
# OR THIS:
some_class.updating_something_because_it_needs_to_be_updated()
# Another class description file and its method
class Some_class():
def __init__(self):
def updating_something_because_it_needs_to_be_updated(self):
something is happening
...