Hello pythons,
I have little problem with understanding conversions in python. I've
written a little class - nothing much, just to try out Python a little
- containing the following method:
def __repr__(self):
"""Serializ es the note.
Currently the format of notes isn't decided upon. XML output
is
projected."""
return "Due: " + str(self.dateDu e) + \
"\nDate: " + str(self.dateCr eated) + \
"\nSubject: " + self.subject + \
"\n" + self.content
The fields "dateDue" and "dateCreate d" contain datetime.date objects.
Now when I try to serialize the whole thing:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "notes.py", line 81, in __repr__
return "Due: " + str(self.dateDu e) + \
TypeError: cannot concatenate 'str' and 'datetime.date' objects
I tryed different variant before I wrapped "self.dateD ue" in a str()
constructor:
I tried to put it in brackets, or call its .isoformat() method.
Nothing works. It still complains that I was trying to concatenate a
string with a date, but I really wanna concatenate a string with a
string!
Could anyone please tell me what I am doing wrong?
Greetings,
Björn
I have little problem with understanding conversions in python. I've
written a little class - nothing much, just to try out Python a little
- containing the following method:
def __repr__(self):
"""Serializ es the note.
Currently the format of notes isn't decided upon. XML output
is
projected."""
return "Due: " + str(self.dateDu e) + \
"\nDate: " + str(self.dateCr eated) + \
"\nSubject: " + self.subject + \
"\n" + self.content
The fields "dateDue" and "dateCreate d" contain datetime.date objects.
Now when I try to serialize the whole thing:
>>myNote
File "<stdin>", line 1, in ?
File "notes.py", line 81, in __repr__
return "Due: " + str(self.dateDu e) + \
TypeError: cannot concatenate 'str' and 'datetime.date' objects
I tryed different variant before I wrapped "self.dateD ue" in a str()
constructor:
I tried to put it in brackets, or call its .isoformat() method.
Nothing works. It still complains that I was trying to concatenate a
string with a date, but I really wanna concatenate a string with a
string!
Could anyone please tell me what I am doing wrong?
Greetings,
Björn
Comment