问题描述
我一直在寻找解决方案,但没有找到,所以这是我的代码:
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!