我有一个看起来像这样的项目:
PyBlob
|- __init__
|- Actor
|- Blob
|- Bullet
|- main
|- Player
|- Scene
|- utils
|- Zombie
__init__.py
import sys, pygame, cmath
from Actor import Actor
from Blob import Blob
from Bullet import Bullet
from Player import Player
from Scene import Scene
from utils import *
from Zombie import Zombie
实用程序.py
MAGIC_PINK = (255, 0, 255)
# plus a small handful of utility functions
斑点.py
from PyBlob import *
class Blob:
def __init__(self, radius, body_colour=(0,0,0), face_colour=(255,255,0)):
self.body = pygame.Surface((2*radius, 2*radius))
self.face = pygame.Surface((2*radius, 2*radius))
self.body.set_colorkey(MAGIC_PINK)
#rest of module omitted for brevity
这会导致错误:
NameError: global name 'MAGIC_PINK' is not defined
导入类似乎工作正常,所以很明显我对这个 MAGIC_PINK 变量做错了。