在我的课堂我有错误,其中“__str__返回非字符串”,但显示输出
def __str__(self):
print "abc"
当我创建这个类的一个对象a
,并键入print a
,它打印abc
(正确),但那么也给出了输出
Traceback (most recent call last):
File "<pyshell#23>", line 1, in <module>
print a
TypeError: __str__ returned non-string (type NoneType)
我该如何解决它?