是什么导致此AttributeError? [英] What is causing this AttributeError?
问题描述
我一直在寻找解决方案,但没有找到解决方案,所以这是我的代码:
I've been looking all over for a solution but haven't found one so here's my code:
class snakeGame:
def _init_(self):
pygame.init()
self._isRunning = False
self._surface = None
self.drawList = None
self.updateList = None
self.resources = loadResources()
self.width = 640
self.height = 400
self.size = [self.width,self.height]
def run(self,args):
self._surface = pygame.display.set_mode(self.size,pygame.HWSURFACE | pygame.DOUBLEBUF)
self._isRunning = True
调用"run"方法时python抛出AttributeError,告诉我snakeGame实例没有属性"size"
when the "run" method is called python throws an AttributeError telling me that the instance of snakeGame has no attribute "size"
我是python的新手,并且有NNNOOO提示为什么看不到它.有人可以帮我吗?
i'm pretty new to python and have NNNOOO clue why it doesn't see it. Can someone help me?
这也是我代码中的一小段.如果您需要更多,请询问.我只是想知道问题可能出在这里的某个地方.
also this is only a small snippet from the my code. If you need more, please ask. I just figured the problem was probably in here somewhere.
推荐答案
在init函数之前和之后,需要两个下划线: __ init __
. _init _
没有特殊含义,并且在构造对象时不会被调用.
You need two underscores before and after the init function: __init__
. _init_
has no special meaning and isn't being called when your object is constructed.
这篇关于是什么导致此AttributeError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!