在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Python/ python中自己的類不能被導(dǎo)入

python中自己的類不能被導(dǎo)入

我自己編寫了一個(gè)類
class Settings():

def __init__(self):
    self.screen_width=1200
    self.screen_height=800
    self.bg_color=(230,230,230)

然后我想在引用
import sys
import pygame

from settings import Settings
def run_game():

pygame.init()
ai_settings=Settings()
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:
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            sys.exit()
    
    screen.fill(ai_settings.bg_color)
    pygame.display.flip()
    

run_game()

但是最后的結(jié)果是這樣的
Traceback (most recent call last):
File "alien_invasion", line 5, in <module>

from settings import Settings

ModuleNotFoundError: No module named 'settings'

我不知道到底是什么原因,是path問(wèn)題還是我的設(shè)置有問(wèn)題,我用的是geany

回答
編輯回答
不舍棄

你的settings.py和alien_invasion.py在同一路徑下? 如果不是需要加到path里才行

import sys
sys.path.append('../my_settings_path')
from settings import Settings
2017年9月17日 20:26