【发布时间】:2021-08-30 18:22:15
【问题描述】:
这是 Alien_invasion.py 的内容:
import pygame
import sys
#here im importing the class from the settings class
from settings import Settings
def run_game():
ai_settings = Settings()
pygame.init()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Alien Invasion")
bg_color = (230, 230, 230)
while True:
...
run_game()
这在 settings.py 中:
class Settings():
def __init__(self):
self.screen_width = 1200
self.screen_height = 800
self.bg_color = (230, 230, 230)
尝试运行 Alien_invasion.py 时,出现以下错误:
ImportError: cannot import name 'Settings' from 'settings'
【问题讨论】:
-
您确定这两个文件在同一个目录中吗?我无法重现错误。
标签: python class module runtime-error