The first import
will load the module pygame within the scope (namespace) of your file/module while the second will only load the class "Sprite" in it. Actually the second import
is there as a shortcut since nothing stops you from writing:
import pygame
class Bullet(pygame.sprite.Sprite):
...
Perhaps only practicality since "Sprite" is much smaller than "pygame.sprite.Sprite". :-)
For from the point of view of language they correspond to the same object:
>>> import pygame
pygame 2.0.1 (SDL 2.0.14, Python 3.8.6)
Hello from the pygame community. https://www.pygame.org/contribute.html
t>>> id(pygame.sprite.Sprite)
43004016
>>> from pygame.sprite import Sprite
>>> id(Sprite)
43004016
from pygame.sprite import Sprite
means: From the pygame.Prite module import the Sprite class. <(-_-)>– Augusto Vasques
Sprite is a submodule ?
– kyo129
What part of From the pygame.Prite module import the Sprite class. you don’t understand?
– Augusto Vasques
is the pygame.Sprite
– kyo129
You have the pygame lib, in addition to the main lib it divided into several other modules, one for each subject. So it can be understood as a specialized submodule, but in reality it’s built-in or nested modules.
– Augusto Vasques