TypeError:object .__ new__没有参数

时间:2013-11-16 17:10:49

标签: python python-3.3

以下是代码:

class Display:
    def ___init___(self,width,height):
        self.screenWidth = width
        self.screenHeight = height
        #self.background1 = pygame.image.load("background1.png")
        #self.backplace = self.background1.get_rect()
        # Initialize screen

        self.size = self.width, self.height = self.screenWidth, self.screenHeight
        self.screen = pygame.display.set_mode(self.size)
        # Loaded only once to save time
        #self.healthImage = pygame.image.load("healthbetter.png").convert_alpha()
        self.somethingChanged = False   # Nothing changed, no need to draw screen
        self.scrollOffset = 0
        mathclass = Mathclass(self.screen)

这是错误:

"Traceback (most recent call last):
  File "C:\Documents and Settings\Noam\My Documents\games by me\first project\first project.py", line 302, in <module>
    display = Display(640,480)
TypeError: object.__new__() takes no parameters"

我无法找到任何可以帮助我解决此特定错误的内容。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:4)

magic methods只需要两个下划线时,你已经添加了一组额外的下划线,而是试试这个:

def __init__(self,width,height):