|
本帖最后由 强人锁男 于 2018-9-18 16:04 编辑
我有四个不同的文件:main,vector,entity和physics。)
main:
- import time
- from entity import Ent
- from vector import Vect
- #the rest just creates an entity and prints the result of movement
复制代码
entity:
- 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
复制代码
vector:
- from math import *
- class Vect:
- #holds i, j, k, and does vector math
- physics:
- 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 <module>
- from entity import Ent
- File ".../entity.py", line 5, in <module>
- from physics import Physics
- File ".../physics.py", line 2, in <module>
- from entity import Ent
- ImportError: cannot import name Ent
复制代码
我是Python的新手,但已经使用C ++很长一段时间了。我猜这个错误是由于导入entity两次,一次是在main中,另一次在physics中,,但我不知道如何解决。有人可以帮忙吗? |
|