Mam ten fragment kodu, który tworzy nowy note..WHen próbuję wydrukować pojawia się następujący błąd, mimo że drukuje wyświetlamyPython: "TypeError: __str__ zwrócił ciąg znaków", ale nadal drukuje na wyjściu?
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)
note.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)
Tego właśnie potrzebuję! Jak zapisać tę odpowiedź na przyszłość ...> ??? – flowera