Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5038
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'instance,': 0.05; 'function,': 0.07; 'terry': 0.07; 'python': 0.07; '>>>>': 0.09; 'called.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'str': 0.09; 'subject:string': 0.09; 'pm,': 0.11; 'def': 0.13; 'wrote:': 0.14; '4:25': 0.16; 'reedy': 0.16; 'subject:joining': 0.16; 'seems': 0.21; 'jan': 0.22; 'header:In-Reply-To:1': 0.22; 'example': 0.24; 'calling': 0.25; 'statement': 0.26; 'work.': 0.27; "doesn't": 0.28; 'skip:" 30': 0.29; 'class': 0.29; '"you': 0.29; 'work:': 0.29; 'implement': 0.30; "won't": 0.30; 'does': 0.31; "skip:' 10": 0.32; 'to:addr:python-list': 0.32; "i've": 0.33; 'implemented': 0.33; 'header:X-Complaints-To:1': 0.34; 'skip:" 10': 0.34; 'post': 0.34; 'header:User-Agent:1': 0.35; 'explicit': 0.35; 'strings': 0.38; 'but': 0.38; 'received:org': 0.38; 'to:addr:python.org': 0.39; 'header:Mime-Version:1': 0.39; 'header:Received:5': 0.40; 'special': 0.66; 'subject:Custom': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Terry Reedy <tjreedy@udel.edu> |
| Subject | Re: Custom string joining |
| Date | Mon, 09 May 2011 19:16:24 -0400 |
| References | <254518825.20110507153133@bitdefender.com> <BANLkTim-94Zfq1o0P5DnAKfywR=cTm2z9Q@mail.gmail.com> <4DC84B2E.9090209@free.fr> <354289288.20110509232527@bitdefender.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | rain.gmane.org |
| User-Agent | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10 |
| In-Reply-To | <354289288.20110509232527@bitdefender.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1362.1304982995.9059.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1304982995 news.xs4all.nl 41103 [::ffff:82.94.164.166]:57999 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5038 |
Show key headers only | View raw
On 5/9/2011 4:25 PM, Claudiu Popa wrote:
> I already told in the first post that I've implemented __str__ function,
> but it doesn't seems to be automatically called.
No, Python does not auto-coerce to strings (only between numbers).
You have to be explicit by calling str. Karim's statement "You just have
to implement __str__() python special method for your "custom_objects".
" means that str will then work.
> 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])
print('\n'.join(str(ob) for ob in [a(0), a(1), a(None)]))
magic_function_0
magic_function_1
magic_function_None
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Custom string joining Terry Reedy <tjreedy@udel.edu> - 2011-05-09 19:16 -0400
csiph-web