我有四个不同的文件,分别命名为:main,vector,entity和physics。我不会发布所有代码,而只会发布导入代码,因为我认为这就是错误所在。(如果需要,我可以发布更多信息)
主要:
import time
from entity import Ent
from vector import Vect
#the rest just creates an entity and prints the result of movement
实体:
from vector import Vect
from physics import Physics
class Ent:
#holds vector information and id
def 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 Ent
class 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
from entity import Ent
File ".../entity.py", line 5, in
from physics import Physics
File ".../physics.py", line 2, in
from entity import Ent
ImportError: cannot import name Ent
我对Python非常陌生,但是已经使用C ++了很长时间。我猜测该错误是由于两次导入实体引起的,一次是在主体中,一次是在物理中,但是我不知道解决方法。有人可以帮忙吗?
如果觉得《python nameerror import_Python-ImportError:无法导入名称X》对你有帮助,请点赞、收藏,并留下你的观点哦!