0
어쩌면 바보 같은 질문 일지 모르지만 어쨌든 물어볼 것입니다. 나는 생물체 파일과 시뮬레이션 파일을 가지고 있는데, 각각은 같은 이름의 클래스를 포함하고있다. Simulation 클래스의 init에서 두 개의 Creature 객체를 초기화해야합니다. 나는 생물체 파일을 가져 왔지만 생물체를 시도했을 때 .Creature()를 얻었습니다.python, 다른 파일에있는 객체의 인스턴스
Traceback (most recent call last):
File "/Users/lego90511/Documents/workspace/creatureSim/simulation.py", line 2, in <module>
import creature
File "/Users/lego90511/Documents/workspace/creatureSim/creature.py", line 3, in <module>
import simulation
File "/Users/lego90511/Documents/workspace/creatureSim/simulation.py", line 86, in <module>
sim = Simulation(5)
File "/Users/lego90511/Documents/workspace/creatureSim/simulation.py", line 6, in __init__
self.creatures = {creature.Creature(4, 4, 3, 4, 4, 3, 10):"", creature.Creature(4, 4, 3, 4, 4, 3, 10):"", }
AttributeError: 'module' object has no attribute 'Creature'"
내가 뭘 잘못하고 있니?
다음은 관련 코드입니다 :
시뮬레이션 :
import creature
from random import randint
class Simulation():
def __init__(self, x):
self.creatures = {creature.Creature():"", creature.Creature():"", }
...
생물 :
class Creature:
def __init__(self, social, intelligence, sensory, speed, bravery, strength, size):
self.traits = [social, intelligence, sensory, speed, bravery, strength]
...
코드 실행 중 오류가 발생하지 않습니다. – Bemmu
내 PC에서 코드를 실행하면 오류가 발생하지 않지만 충분한 인수를 Creature에게 주어야합니다. – zhangyangyu
나는 무엇이든 더 드러내는 완전한 오류 텍스트를 추가했다. 그것은 파이썬 3.3을 사용하여 처리해야 할 것이 있습니까? – EasilyBaffled