Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5024
| Date | 2011-05-09 23:25 +0300 |
|---|---|
| From | Claudiu Popa <cpopa@bitdefender.com> |
| Subject | Re: Custom string joining |
| References | <254518825.20110507153133@bitdefender.com> <BANLkTim-94Zfq1o0P5DnAKfywR=cTm2z9Q@mail.gmail.com> <4DC84B2E.9090209@free.fr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1355.1304972738.9059.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Custom string joining Claudiu Popa <cpopa@bitdefender.com> - 2011-05-09 23:25 +0300 Re: Custom string joining Martineau <ggrp2.20.martineau@dfgh.net> - 2011-05-09 14:38 -0700
csiph-web