Custom string joining
Claudiu Popa
cpopa at bitdefender.com
Mon May 9 16:25:27 EDT 2011
Hello Karim,
> You just have to implement __str__() python special method for your
> "custom_objects".
> Regards
> Karim
>> Cheers,
>> Chris
>> --
>> http://rebertia.com
I already told in the first post that I've implemented __str__ function, but it doesn't
seems to be automatically called.
For instance, the following example won't work:
>>> class a:
def __init__(self, i):
self.i = i
def __str__(self):
return "magic_function_{}".format(self.i)
>>> t = a(0)
>>> str(t)
'magic_function_0'
>>> "".join([t])
Traceback (most recent call last):
File "<pyshell#13>", line 1, in <module>
"".join([t])
TypeError: sequence item 0: expected str instance, a found
--
Best regards,
Claudiu
More information about the Python-list
mailing list