有人可以解释一下这个奇怪的 Pygame 导入约定吗? [英] Can someone please explain this weird Pygame importing convention?

查看:29
本文介绍了有人可以解释一下这个奇怪的 Pygame 导入约定吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到人们通常像这样导入 Pygame:

I see that people usually import Pygame like this:

import pygame
from pygame.locals import *

我不明白第二行是什么意思.如果我们已经导入了整个 Pygame,为什么还要导入 pygame.locals?导入后 Pygame 不是已经包含它了吗?

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?

推荐答案

import pygame

将 pygame 模块导入pygame"命名空间.

imports the pygame module into the "pygame" namespace.

from pygame.locals import *

将 pygame.locals 中的所有名称复制到您当前的命名空间中.这不是必需的,但可以节省您的输入时间.

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

这篇关于有人可以解释一下这个奇怪的 Pygame 导入约定吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆