Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'parameters': 0.04; 'mrab': 0.05; 'string': 0.09; 'character,': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; 'commas:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'there?': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'aug': 0.22; 'putting': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'long,': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'tim': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'chase': 0.31; 'there,': 0.34; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'so,': 0.37; 'list': 0.37; 'does': 0.39; 'how': 0.40; 'experts': 0.60; 'problems.': 0.60; 'actually,': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=cb7kr3FqElTd4Ciu1u9Yr1R0pOSrw6jOiNPRiJg4lXE=; b=u7DphaLoJsZm698dbm0idIWroyO3MnmxlmJrihkrjQ4vEq+RF0ttd2lJQ5djwfsG85 yM1kLLAVfuY3IOhPb6wXM1o6hCOu2kVFCkwjKvXe4H+JHPCGB7QceZ6W3X4ITWpS5u4t OBsns/MI2pWbggTInBK03ylITK/HYRkDX1EB8FVr1+zGQM5l+t5B6Wyl/M4Qh2g38cG5 1eWy8RtyOYls5TQuQDcu5vRHCSPyPkqEX31n4zZ+1918E3OigqQ2JDrgWGjJaN3IGVam 3tGpOxkMnDqxiy2fEM7NotOQObK+TMymQE+tIuhMnniZUUCL5dyNDtsyrQTG/a8Bcwcq dMYg== MIME-Version: 1.0 X-Received: by 10.50.176.169 with SMTP id cj9mr1247059igc.14.1409180131511; Wed, 27 Aug 2014 15:55:31 -0700 (PDT) In-Reply-To: <20140827174446.11a1cd01@bigbox.christie.dr> References: <55bab2a0-e0bc-4398-90b4-c9937498f5d8@googlegroups.com> <53FE5EDD.9020502@mrabarnett.plus.com> <20140827174446.11a1cd01@bigbox.christie.dr> Date: Thu, 28 Aug 2014 08:55:31 +1000 Subject: Re: python string, best way to concat From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409180134 news.xs4all.nl 2853 [2001:888:2000:d::a6]:48951 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77173 On Thu, Aug 28, 2014 at 8:44 AM, Tim Chase wrote: > On 2014-08-27 23:42, MRAB wrote: >> How many parameters are there? len(self.param) >> >> Make that many placeholders and then join them together with commas: >> >> ', '.join(['?'] * len(self.param)) > > I prefer the clarity of Peter Otten's suggestion of > > ', '.join('?' * len(self.param)) > > over the mild obscurity of putting it in a list before multiplying. Actually, I'd go the other way. This code has a possibly-surprising limitation: it works only if the replicated string is one character long, and in Python 3, that really does mean character, not byte. Of course, Python experts know that it works on string iterability, and know exactly why b'?' wouldn't work there, but putting it in a list solves both problems. So, I'd say the ['?'] code is less fragile. ChrisA