小编Bra*_*rad的帖子

Python - TypeError:未绑定方法

所以这个Python问题一直给我带来问题,因为我已经尝试将代码重构为不同的文件.我有一个名为object.py的文件,其中相关的代码是:

class Object:
#this is a generic object: the player, a monster, an item, the stairs...
#it's always represented by a character on screen.
def __init__(self, x, y, char, color):
    self.x = x
    self.y = y
    self.char = char
    self.color = color

def move(self, dx, dy):
    #move by the given amount, if the destination is not blocked
    #if not map[self.x + dx][self.y + dy].blocked:
        self.x += dx
        self.y += dy
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试专门编译此文件时,我收到此错误:

TypeError: unbound method __init__() must be called with Object …
Run Code Online (Sandbox Code Playgroud)

python initialization attributeerror

5
推荐指数
1
解决办法
5950
查看次数

标签 统计

attributeerror ×1

initialization ×1

python ×1