Python 属性错误:模块'';没有属性'';

Python 属性错误:模块'';没有属性'';,python,python-import,Python,Python Import,我有以下文件: biomes.py import animals ... class woodsBiome(baseBiome): # I do stuff def __init__(self): self.animals = animals.generateAnimals(5) def generateAnimals(quantity): # I do stuff 动物。py import animals ... class woodsBio

我有以下文件:

biomes.py

import animals

...

class woodsBiome(baseBiome):
    # I do stuff
    def __init__(self):
        self.animals = animals.generateAnimals(5)
def generateAnimals(quantity):
    # I do stuff
动物。py

import animals

...

class woodsBiome(baseBiome):
    # I do stuff
    def __init__(self):
        self.animals = animals.generateAnimals(5)
def generateAnimals(quantity):
    # I do stuff
当我在
biomes.woodsBiome
上运行
\uuuu init\uuuuu
时,它在
动物生成动物(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'
回溯(最近一次呼叫最后一次):
文件“game.py”,第10行,在
进口动物
文件“/path/to/files/anivers.py”,第4行,在
从游戏进口模具
文件“/path/to/files/game.py”,第22行,在
areaMap=生物群落生成地图(xMax,yMax)
文件“/path/to/files/biomes.py”,generateMap中的第85行
生物群落学家=[Woodsbome()、沙漠群落()、野外群落()]
文件“path/to/files/biomes.py”,第41行,在__
self.animals=animals.generateAnimals(5)
AttributeError:模块“animals”没有属性“generateAnimals”
我有一种感觉,很明显我错过了什么。谁能给我指一下正确的方向吗


谢谢。

我还不能对此发表评论,所以这里有一个问题

在那里的代码中,我注意到您的类调用
\uuuu init\uuuuu()
没有自我。你的代码是这样的吗?把这个类称为

\uuuu初始化(自)


有什么变化吗?

我还不能发表评论,所以这里有一个问题

在那里的代码中,我注意到您的类调用
\uuuu init\uuuuu()
没有自我。你的代码是这样的吗?把这个类称为

\uuuu初始化(自)


有什么变化吗?

听起来像是循环导入问题。这可能是一些不同的问题。你是在像水蟒或树冠这样的地方运行吗?是的。
animals.py
是否也导入
biomes
?您是否真的可以包含完整的回溯并删除
?因此
animals.py
是否(间接)导入
biomes
。你不能那样做。重新组织您的代码,使您的模块排列在“层”中,并且每个层仅从其自身下面的层导入。听起来像是一个循环导入问题。这可能是一些不同的事情。你是在像水蟒或树冠这样的地方运行吗?是的。
animals.py
是否也导入
biomes
?您是否真的可以包含完整的回溯并删除
?因此
animals.py
是否(间接)导入
biomes
。你不能那样做。重新组织你的代码,使你的模块被安排在“层”中,每一层只从它下面的层导入。不,这只是我的错误。修好了。不,这只是我的错。解决这个问题。