Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
大家好,我想知道为什么这段代码有效
from pygame.locals import * print QUIT
这不起作用
import pygame print pygame.locals.QUIT
locals是 的嵌套子包pygame,您必须先导入它:
locals
pygame
import pygame.locals
它不是pygame自身的属性;仅当pygame/__init__.py文件本身要执行时才有效from . import locals。
pygame/__init__.py
from . import locals
你必须导入pygame.locals,而不是pygame。包内的模块不会因为您导入包而自动导入。
pygame.locals