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
提交
取消