我有这段代码可以创建一个新注释..当我尝试打印时,即使它打印输出,我也会收到以下错误
Error:
C:\Python27\Basics\OOP\formytesting>python notebook.py
Memo=This is my first memo, Tag=example
Traceback (most recent call last):
File "notebook.py", line 14, in <module>
print(firstnote)
TypeError: __str__ returned non-string (type NoneType)
笔记.py
import datetime
class Note:
def __init__(self, memo, tags):
self.memo = memo
self.tags = tags
self.creation_date = datetime.date.today()
def __str__(self):
print('Memo={0}, Tag={1}').format(self.memo, self.tags)
if __name__ == "__main__":
firstnote = Note('This is my first memo','example')
print(firstnote)