所以这个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)