2017-10-17 149 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

不,這只是我的錯誤。解決這個問題。 –

相關問題