Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

python - Can someone please explain this weird Pygame importing convention?

I see that people usually import Pygame like this:

import pygame
from pygame.locals import *

I don't understand what's the second line for. If we already imported the whole of Pygame, why import pygame.locals? Doesn't Pygame already include it once it's imported?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
import pygame

imports the pygame module into the "pygame" namespace.

from pygame.locals import *

copys all names in pygame.locals into your current namespace. This is not neccessary, but saves you typing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...