Alan Alves de Oliveira
Alan Alves de Oliveira

Reputation: 713

importing modules locals variables in another modules

Hi everyone, i would like to know why this code works

from pygame.locals import *
print QUIT

and this don't works

import pygame
print pygame.locals.QUIT

Upvotes: 0

Views: 115

Answers (2)

BrenBarn
BrenBarn

Reputation: 251508

You have to import pygame.locals, not pygame. Modules inside a package aren't automatically imported just because you import the package.

Upvotes: 0

Martijn Pieters
Martijn Pieters

Reputation: 1124000

locals is a nested sub-package of pygame, you'll have to import it first:

import pygame.locals

It is not an attibute of pygame itself; that only works if the pygame/__init__.py file itself were to do from . import locals.

Upvotes: 1

Related Questions