您好,当我尝试打印我的对象时,我遇到了 __str__ 问题。解释器告诉我“TypeError:格式字符串的参数不足”
这是我要运行的代码!
'My Practice Class'
class Directory:
'A Simple Directory Class'
def __init__(self, name, parent):
self.name = name
self.parent = parent
def __str__(self):
return 'I am %s a Child directory of %s' % (self.name, self.parent)
def __repr__(self):
return 'Directory(%r)' % self.name
print a
Traceback (most recent call last):
File "<\stdin>", line 1, in <\module>
File "myclass.py", line 14, in \__str\__
def \__repr\__(self):
TypeError: not enough arguments for format string
谢谢