Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Tim Chase Newsgroups: comp.lang.python Subject: Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Date: Sun, 8 May 2016 18:37:38 -0500 Lines: 58 Message-ID: References: <20160508183738.2f551043@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de TIlxkvISAxvDU7AAaSmQjATAmix4WpuQoNX4YcjiJPhw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:skip:c 10': 0.07; 'lst': 0.09; 'specifying': 0.09; 'subject: \n ': 0.15; '-tkc': 0.16; 'dfs': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'quadratic': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'string': 0.17; '(you': 0.23; 'header:In-Reply- To:1': 0.24; 'once,': 0.29; "i'm": 0.30; 'usually': 0.33; 'replaced': 0.35; 'list,': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'doing': 0.38; 'subject:the': 0.39; 'build': 0.40; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'behavior': 0.61; 'within': 0.64; 'received:23': 0.84; 'suboptimal.': 0.84; 'subject:this': 0.85; 'subject:you': 0.85 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1462752035149:3279711855 X-MC-Ingress-Time: 1462752035148 In-Reply-To: X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20160508183738.2f551043@bigbox.christie.dr> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:108398 While I'm not Steven... On 2016-05-08 19:10, DFS wrote: > sSQL = "line 1\n" > sSQL += "line 2\n" > sSQL += "line 3" If you're only doing it once, it's adequate. If you're doing it within a loop for thing in some_iter(): s = "line1\n" s += "line2\n" s += "line3" use(s, thing) it's suboptimal. Solutions include hoisting it out of the loop: s = "line1\n" s += "line2\n" s += "line3" for thing in some_iter(): use(s, thing) and just specifying it with a multi-line string (still better off hoisted out of the loop): s = """line1 line2 line3""" for thing in some_iter(): use(s, thing) If you're accruing in a loop s = "" for thing in some_iter(): s += mung(thing) then that's a bad code-smell (you get quadratic behavior as the strings are constantly resized), usually better replaced with s = "".join(mung(thing) for thing in some_iter()) or build them up as a list, then join the results: lst = [] for thing in some_iter(): if should_use(thing): lst.append(thing) s = "\n".join(lst) -tkc