您好,当我尝试打印对象时,__ 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
谢谢
[删除评论,因为这可能是一个有用的路标问题]
如果要导入正在调用的模块
import xxx
第二次不重新导入更改的文件(python试图变得更聪明,看到您已经将该模块加载了一些短程序)。发生的事情是您正在更改文件,但是python从未看到过这些更改。
重新加载模块调用
reload(xxx)
如果您将事物导入为
from xxx import yyy
通话reload xxx
不会影响yyy
您需要执行的操作
reload(xxx)
yyy = xxx.yyy
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句