ImportError:無法導入名稱X我有四個不同的文件名為:主,矢量,實體和物理。我不會發布所有的代碼,僅僅是導入,因為我認為這就是錯誤所在。(如果你愿意,我可以張貼更多)主要:import timefrom entity import Entfrom vector import Vect#the rest just creates an entity and prints the result of movement實體:from vector import Vectfrom physics import Physicsclass Ent:
#holds vector information and iddef tick(self, dt):
#this is where physics changes the velocity and position vectors矢量:from math import *class Vect:
#holds i, j, k, and does vector math物理學:from entity import Entclass Physics:
#physics class gets an entity and does physics calculations on it.然后從main.py運行,得到以下錯誤:Traceback (most recent call last):File "main.py", line 2, in <module>
from entity import EntFile ".../entity.py", line 5, in <module>
from physics import PhysicsFile ".../physics.py", line 2, in <module>
from entity import EntImportError: cannot import name Ent我對Python非常陌生,但我使用C+已經很長時間了。我猜想,這個錯誤是由于兩次導入實體造成的,一次在主,一次在物理中,但我不知道有什么解決辦法。有人能幫忙嗎?
3 回答

慕無忌1623718
TA貢獻1744條經驗 獲得超4個贊
import SomeModuledef someFunction(arg): from some.dependency import DependentClass

青春有我
TA貢獻1784條經驗 獲得超8個贊
vector
entity
from x import y
import x y = x.ydel x
a = module() # import a# rest of modulea.update_contents(real_a)
import x
import xclass cls: def __init__(self): self.y = x.y
y = x.y
添加回答
舉報
0/150
提交
取消