Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5024

Re: Custom string joining

Path csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cpopa@bitdefender.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'instance,': 0.05; 'function,': 0.07; 'python': 0.07; 'called.': 0.09; 'str': 0.09; 'subject:string': 0.09; '>>>': 0.12; 'def': 0.13; 'subject:joining': 0.16; 'traceback': 0.16; '(most': 0.16; 'cheers,': 0.20; 'seems': 0.21; 'header:In-Reply-To:1': 0.22; 'last):': 0.23; 'example': 0.24; 'chris': 0.27; "doesn't": 0.28; 'skip:" 30': 0.29; 'class': 0.29; 'work:': 0.29; 'implement': 0.30; "won't": 0.30; 'typeerror:': 0.31; "skip:' 10": 0.32; 'to:addr:python-list': 0.32; "i've": 0.33; 'implemented': 0.33; 'skip:" 10': 0.34; 'post': 0.34; 'file': 0.35; '"",': 0.35; 'sequence': 0.38; 'but': 0.38; 'to:addr:python.org': 0.39; 'best': 0.60; 'special': 0.66; 'received:(helo localhost)': 0.73; 'subject:Custom': 0.84; 'received:ro': 0.91
Date Mon, 9 May 2011 23:25:27 +0300
From Claudiu Popa <cpopa@bitdefender.com>
X-Priority 3 (Normal)
To python-list@python.org
Subject Re: Custom string joining
In-Reply-To <4DC84B2E.9090209@free.fr>
References <254518825.20110507153133@bitdefender.com> <BANLkTim-94Zfq1o0P5DnAKfywR=cTm2z9Q@mail.gmail.com> <4DC84B2E.9090209@free.fr>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding quoted-printable
X-BitDefender-Spam No (0)
X-BitDefender-SpamStamp v1, build 2.8.97.149134, SQMD Hits: InvalidIPBytes34 97.192.25.0, rbl score: 0(0), bayes score: 500(0), pbayes score: 500(0), neunet score: 0(0), flags: [NN_LEGIT_BITDEFENDER; NN_LAST_COLON; NN_LEGIT_MAILING_LIST_TO], SQMD: 4082bbd4468955e41033a8a5cadf3c08.fuzzy.fzrbl.org, total: 0(775)
X-BitDefender-Scanner Clean, Agent: BitDefender qmail 3.1.0 on elfie.dsd.hq, sigver: 7.37419
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.1355.1304972738.9059.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 82.94.164.166
X-Trace 1304972738 news.xs4all.nl 81484 [::ffff:82.94.164.166]:39324
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5024

Show key headers only | View raw


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 | NextNext in thread | Find similar | Unroll thread


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