![](/img/trans.png)
[英]Python class error TypeError: __init__() missing 1 required positional argument: 'self'
[英]Using pygame and making class for a character, keep getting error: TypeError: __init__() missing 1 required positional argument: 'self'
使用此代碼:
import pygame
class Creature(pygame.sprite.Sprite):
pygame.sprite.Sprite.__init__()
class Human(Creature):
def __init__(self):
super.__init__()
self.image = pygame.image.load('resources/images/Protag.png')
pygame.draw(self.image)
self.rect = self.image.get_rect()
def moveRight(self, pixels):
self.rect.x += pixels
def moveLeft(self, pixels):
self.rect.x -= pixels
我一直在標題中得到錯誤。 我在網上遵循了教程,但仍然遇到此錯誤。 有什么想法嗎?
在您的Human
類中,在__init__
函數中將其更改為this(對於Python 2):
super(Human, self).__init__()
如果您使用的是Python 3,則:
super()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.