2017-10-17 83 views
1

我有文件:AttributeError的:模块 '...' 有没有属性 '...'

biomes.py

import animals 

... 

class woodsBiome(baseBiome): 
    # I do stuff 
    def __init__(self): 
     self.animals = animals.generateAnimals(5) 

animals.py

def generateAnimals(quantity): 
    # I do stuff 

当我在biomes.woodsBiome上运行__init__时,它在animals.generateAnimals(5)上失败。它给出:

Traceback (most recent call last): 
    File "game.py", line 10, in <module> 
    import animals 
    File "/path/to/files/animals.py", line 4, in <module> 
    from game import die 
    File "/path/to/files/game.py", line 22, in <module> 
    areaMap = biomes.generateMap(xMax, yMax) 
    File "/path/to/files/biomes.py", line 85, in generateMap 
    biomeList = [woodsBiome(), desertBiome(), fieldBiome()] 
    File "path/to/files/biomes.py", line 41, in __init__ 
    self.animals = animals.generateAnimals(5) 
AttributeError: module 'animals' has no attribute 'generateAnimals' 

我有一种感觉,有什么明显的我失踪了。有人能指出我正确的方向吗?

谢谢。

+0

听起来像一个循环进口问题。 – user2357112

+0

这可能是一些不同的事情。你是用Anaconda还是Canopy来运行它? – roganjosh

+0

是的。 'animals.py'还会导入'生物群落'吗? –

回答

0

我还不能评论,所以这是一个queston。

在那里的代码中,我注意到你的班级在没有自我的情况下调用 __init__() 。这是如何在你的代码?是否调用类的

__init__(self)

改变什么?

+0

不,这只是我的错误。解决这个问题。 –

相关问题