Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'args': 0.04; 'function,': 0.07; 'repeated': 0.07; 'list...': 0.09; 'cc:addr:python-list': 0.10; 'commandline': 0.16; 'concatenate': 0.16; 'eckhardt': 0.16; 'oct': 0.16; 'wrote:': 0.17; 'assuming': 0.22; 'cc:2**0': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'least': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'lines': 0.28; "i'm": 0.29; 'fri,': 0.30; 'received:209.85.210.174': 0.30; '+0200,': 0.33; 'received:gov': 0.33; 'received:google.com': 0.34; 'text': 0.34; 'list': 0.35; 'problem,': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'charset:us-ascii': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'instead': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'content-disposition:inline': 0.60; '26,': 0.65; 'alternative.': 0.84; 'expressive': 0.84; 'subject:better': 0.84 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent :x-gm-message-state; bh=GneoAgI+nYVad5pU6ZFvape18EziW58D7jz5ung30vg=; b=bjLJdYayOPtYPgx0s16o+qcooKABNFV3YmYyJGwD4G2NyyE9VtQDxs5gDHfPUxZ02G BX+sXqIVcI0VkCt/svSvW+X3FiArayPWM30ARSX8jrEnmaV0oAf3HvDdxBvzpU4L2sfP P2UR8/CGpwJzLi33/VRsrUkNe3ptl/suQQQuoEUcbEc3+r3LOBYHIqGtBS5ZlgUz8VAG 2vicox+SUH3VTnsNkx+AoFsGmxnzEpNp9hdgP58QzkKW7JsuzkoJZ4NffDSrUczaaTju KnT2bPGo3ceXcV/CD1BJ7scgNBHWwHzNe1Idg1lGwZdpw4MHpIbm2sjf5D8siV+T7Hg1 BRGQ== Date: Fri, 26 Oct 2012 16:26:02 -0500 From: Tycho Andersen To: Ulrich Eckhardt Subject: Re: better way for ' '.join(args) + '\n'? References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQmZ0fItg9FJVVXvd5XyhEVepM16R7aOiC19DbTdbCu5tpD7AoHqpn/EJCqB/XGNgcENcf3U Cc: python-list@python.org 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351286761 news.xs4all.nl 6846 [2001:888:2000:d::a6]:55935 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32234 On Fri, Oct 26, 2012 at 09:49:50AM +0200, Ulrich Eckhardt wrote: > Hi! > > General advise when assembling strings is to not concatenate them > repeatedly but instead use string's join() function, because it > avoids repeated reallocations and is at least as expressive as any > alternative. > > What I have now is a case where I'm assembling lines of text for > driving a program with a commandline interface. In this scenario, > I'm currently doing this: > > args = ['foo', 'bar', 'baz'] > line = ' '.join(args) + '\n' Assuming it's the length of the list that's the problem, not the length of the strings in the list... args = ['foo', 'bar', 'baz'] args[-1] = args[-1] + '\n' line = ' '.join(args) \t