我有文件:
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上运行biomes.woodsBiome时,它在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'我有种感觉有些明显的东西我错过了。谁能给我指明正确的方向吗?
谢谢。
发布于 2017-10-17 17:46:15
我还不能对此发表评论,所以这里有个问题。
在这里的代码中,我注意到您的类调用了__init__(),而其中没有self。在您的代码中是这样的吗?是否将类称为
__init__(self)
有什么改变吗?
https://stackoverflow.com/questions/46796023
复制相似问题