ฉันมีไฟล์ต่างกันสี่ชื่อ: 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 movementEntity:
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 <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 ++ มาเป็นเวลานาน ฉันคาดเดาว่าข้อผิดพลาดเกิดจากการนำเข้าเอนทิตี้สองครั้งครั้งแรกในหลักและต่อมาในวิชาฟิสิกส์ แต่ฉันไม่รู้วิธีแก้ปัญหา ใครช่วยได้บ้าง
from <module> import <name> from <modlue> import *ดีกว่าที่จะนำเข้าภายใต้โมดูลเนมสเปซเพื่อป้องกันไม่ให้โอกาสของการเขียนทับการอ้างอิงชื่อเหมือนกัน
                EntityและVectorแทนที่จะเป็นEntและVectไม่มีเหตุผลใดที่จะทำให้ชื่อสั้นลง และใช่การใช้งานแล้วimport vector x = vector.Vector(0,0,0)