提问人:Wiktor Rzymski 提问时间:11/18/2023 更新时间:11/18/2023 访问量:54
为什么 python 将 self 视为 str 对象?[关闭]
Why is python treating self as an str object? [closed]
问:
这是交易。 我正在尝试制作一个密室逃脱终端游戏来娱乐,我的问题是我写了这个函数:
def command(command, self):
for object in self.obj:
if object.lookthrough(command):
object.typeout()
break
尝试这样做执行时:弹出错误。
该值在构造函数中调用:example_scene.command(input())
self.obj
def __init__(self, description, *objects):
self.desc = description
self.obj = objects
问题是:我做错了什么?
这里又是代码。 类:
class scene:
def __init__(self, description, *objects):
self.desc = description
self.obj = objects
def typeout(self):
os.system('cls')
for x in self.desc:
sys.stdout.write(x)
sys.stdout.flush()
time.sleep(0.05)
print("\n->", end='')
def command(command, self):
for object in self.obj:
if object.lookthrough(command):
object.typeout()
break
测试结果:example_scene.command(input())
line 17, in command
for object in self.obj:
^^^^^^^^
AttributeError: 'str' object has no attribute 'obj'
答: 暂无答案
评论
self
必须是第一个参数。self
self
self
self