Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 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; 'pm,': 0.11; 'def': 0.13; 'am,': 0.14; 'wrote:': 0.14; '4:25': 0.16; 'subject:joining': 0.16; 'terry,': 0.16; 'thanks,': 0.17; 'seems': 0.21; '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; 'skip:" 10': 0.34; 'post': 0.34; 'explicit': 0.35; 'strings': 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: Tue, 10 May 2011 08:51:55 +0300 From: Claudiu Popa X-Priority: 3 (Normal) To: python-list@python.org Subject: Re: Custom string joining In-Reply-To: References: <254518825.20110507153133@bitdefender.com> <4DC84B2E.9090209@free.fr> <354289288.20110509232527@bitdefender.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: v1, build 2.8.97.149140, SQMD Hits: InvalidIPBytes34 97.54.107.109, rbl score: 0(0), bayes score: 500(0), pbayes score: 500(0), neunet score: 0(0), flags: [NN_LEGIT_BITDEFENDER; NN_LEGIT_MAILING_LIST_TO], SQMD: 23e69cee86c4120b821fddaaef7c08bc.fuzzy.fzrbl.org, total: 0(775) X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.0 on elfie.dsd.hq, sigver: 7.37421 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305006719 news.xs4all.nl 81481 [::ffff:82.94.164.166]:39849 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5056 Hello Terry, Thanks, I understand now. Tuesday, May 10, 2011, 2:16:24 AM, you wrote: > 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 =3D i >> def __str__(self): >> return "magic_function_{}".format(self.i) >>>>> t =3D 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 --=20 Best regards, Claudiu