SORU
12 ŞUBAT 2012, Pazar


İmportError: alamıyor adı X

Dört farklı dosya var adı: ana, vektör, varlık ve fizik. Hatanın nerede olduğunu düşünüyorum çünkü tüm kodu, çoğunlukla sadece ithalat sonrası, vermeyeceğim. Ama eğer isterseniz, daha sonrası.

Ana:

import time
from entity import Ent
from vector import Vect
#the rest just creates an entity and prints the result of movement

Varlık:

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

Vektör:

from math import *
class Vect:
    #holds i, j, k, and does vector math

Fizik:

from entity import Ent
class Physics:
    #physics class gets an entity and does physics calculations on it.

Ben o zaman main.py çalıştırın ve aşağıdaki hatayı alıyorum:

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 için çok yeni değilim, ama uzun zamandır C ile çalışmış. Neden iki kez varlık ithal olduğunu tahmin ediyorum, ana, fizik ve daha sonra bir kez, ama bir çözüm bilmiyorum. Kimseye yardım?

CEVAP
12 ŞUBAT 2012, Pazar


Dairesel bağımlı ithalat var. physics.py Ent tanımlanmış ve physics zaten başlatılıyor entity almaya çalışır dersten önce entity dan ithal ediliyor. entity modülü physics depency çıkarın.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Charles Griffin Gibson

    Charles Grif

    26 NİSAN 2006
  • Kanaal van Dj0fifty

    Kanaal van D

    28 EKİM 2011
  • WOSU Public Media

    WOSU Public

    23 AĞUSTOS 2007