首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:模块‘.’没有属性‘.’

AttributeError:模块‘.’没有属性‘.’
EN

Stack Overflow用户
提问于 2017-10-17 17:39:08
回答 1查看 666关注 0票数 1

我有文件:

biomes.py

代码语言:javascript
复制
import animals

...

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

animals.py

代码语言:javascript
复制
def generateAnimals(quantity):
    # I do stuff

当我在biomes.woodsBiome上运行biomes.woodsBiome时,它在animals.generateAnimals(5)上失败了。它规定:

代码语言:javascript
复制
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'

我有种感觉有些明显的东西我错过了。谁能给我指明正确的方向吗?

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-10-17 17:46:15

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

在这里的代码中,我注意到您的类调用了__init__(),而其中没有self。在您的代码中是这样的吗?是否将类称为

__init__(self)

有什么改变吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46796023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档