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


Groups > comp.lang.python > #77173

Re: python string, best way to concat

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 <rosuav@gmail.com>
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 <rosuav@gmail.com>
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13533.1409180134.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Thu, Aug 28, 2014 at 8:44 AM, Tim Chase
<python.list@tim.thechases.com> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

python string, best way to concat dennisearlevans@gmail.com - 2014-08-27 13:31 -0700
  Re: python string, best way to concat Dan Stromberg <drsalists@gmail.com> - 2014-08-27 15:30 -0700
  Re: python string, best way to concat Peter Otten <__peter__@web.de> - 2014-08-28 00:34 +0200
  Re: python string, best way to concat MRAB <python@mrabarnett.plus.com> - 2014-08-27 23:42 +0100
  Re: python string, best way to concat Tim Chase <python.list@tim.thechases.com> - 2014-08-27 17:44 -0500
  Re: python string, best way to concat Chris Angelico <rosuav@gmail.com> - 2014-08-28 08:55 +1000
  Re: python string, best way to concat Peter Otten <__peter__@web.de> - 2014-08-28 00:59 +0200
  Re: python string, best way to concat MRAB <python@mrabarnett.plus.com> - 2014-08-28 08:12 +0100
  Re: python string, best way to concat peter <peter.mosley@talk21.com> - 2014-08-28 01:30 -0700
    Re: python string, best way to concat Marko Rauhamaa <marko@pacujo.net> - 2014-08-28 11:34 +0300
    Re: python string, best way to concat Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-28 09:43 +0100
    Re: python string, best way to concat Chris Angelico <rosuav@gmail.com> - 2014-08-28 18:58 +1000
    Re: python string, best way to concat Roy Smith <roy@panix.com> - 2014-08-28 08:08 -0400
      Re: python string, best way to concat Mihamina Rakotomandimby <mihamina.rakotomandimby@rktmb.org> - 2014-08-28 15:19 +0300
      Re: python string, best way to concat Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-28 15:48 +0100

csiph-web