Python builtins.ImportError:无法导入名称

时间:2017-05-13 15:04:20

标签: python import pygame circular-dependency

我正在用pygame制作太空射击游戏。 python文件越来越难以理解,因此我决定将这些类拆分为单独的文件,以便于处理。

我有两个文件,Test_Game.py和Playerclass.py。

在Test_Game.py中我做了:

from Playerclass import Player

在Playerclass.py中我做:

from Test_Game import gamedisplay

Player是一个类)

当我运行Test_Game时,我得到的错误是:

Traceback (most recent call last):
  File "C:/Users/Home/Documents/Python/Programs and tutorials/Pygame/Own programs/Programs i've given up on/Space shooter 3 - Defender!/Test_Game.py", line 10, in <module>
    from Playerclass import Player
  File "C:\Users\Home\Documents\Python\Programs and tutorials\Pygame\Own programs\Programs i've given up on\Space shooter 3 - Defender!\Playerclass.py", line 3, in <module>
    from Test_Game import gamedisplay
  File "C:\Users\Home\Documents\Python\Programs and tutorials\Pygame\Own programs\Programs i've given up on\Space shooter 3 - Defender!\Test_Game.py", line 10, in <module>
    from Playerclass import Player
builtins.ImportError: cannot import name 'Player'

感谢所有帮助。

0 个答案:

没有答案
相关问题