Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108474
| From | Stephen Hansen <me+python@ixokai.io> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? |
| Date | 2016-05-10 09:42 -0700 |
| Message-ID | <mailman.566.1462898581.32212.python-list@python.org> (permalink) |
| References | <ngogql$bgm$1@dont-email.me> <5730420b$0$1509$c3e8da3$5496439d@news.astraweb.com> <ngt1aa$j34$1@dont-email.me> <1462898578.1471033.603720241.686524F7@webmail.messagingengine.com> |
On Tue, May 10, 2016, at 09:16 AM, DFS wrote:
> But no, "master", your answers are incorrect. What's wrong with that
> concat statement is that += concatenation is frowned upon by python's
> creator, and is not recommended (in PEP8):
>
> <quote>
> Code should be written in a way that does not disadvantage other
> implementations of Python (PyPy, Jython, IronPython, Cython, Psyco, and
> such).
>
> For example, do not rely on CPython's efficient implementation of
> in-place string concatenation for statements in the form a += b or a = a
> + b . This optimization is fragile even in CPython (it only works for
> some types) and isn't present at all in implementations that don't use
> refcounting. In performance sensitive parts of the library, the
> ''.join() form should be used instead. This will ensure that
> concatenation occurs in linear time across various implementations.
> </quote>
You once again misread PEP8.
Not one of Steven's answers used string concatenation, except for the
implicit literal concatenation, which all other implementations support.
Note:
> sSQL = """line 1
> line 2
> line 3"""
No concatenation. One string literal. Works in all implementations.
> sSQL = "line 1\nline 2\nline 3"
No concatenation. One string literal. Works in all implementations.
>
> sSQL = ("line 1\n"
> "line 2\n"
> "line 3")
Concatenation occurs at compile time, implicitly. Works in all
implementations.
The PEP says when building a string dynamically (that is, adding
together two strings that exist and are separate), use "".join() in
performance sensitive places. It says don't combine two strings with the
addition operator -- because while that's sometimes efficient in
CPython, the language doesn't guarantee it.
You'll notice that the one time Steven combined two strings, it was
implicitly at compile time.
In every Python implementation, it is guaranteed that:
>>> a = "a" "a"
>>> b = "aa"
Are the same. Two+ string literals are implicitly combined into one at
compile time.
> 'master craftswoman' my ass...
Yes, you're being that. Please stop.
--
Stephen Hansen
m e @ i x o k a i . i o
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-08 19:10 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Tim Chase <python.list@tim.thechases.com> - 2016-05-08 18:37 -0500
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Joel Goldstick <joel.goldstick@gmail.com> - 2016-05-08 20:02 -0400
String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-09 02:44 +0200
Re: String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) Chris Angelico <rosuav@gmail.com> - 2016-05-09 12:16 +1000
Re: String concatenation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-09 23:21 +0200
Re: String concatenation Steven D'Aprano <steve@pearwood.info> - 2016-05-10 12:32 +1000
Re: String concatenation Chris Angelico <rosuav@gmail.com> - 2016-05-10 12:42 +1000
Re: String concatenation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-12 17:43 +1000
Re: String concatenation Rustom Mody <rustompmody@gmail.com> - 2016-05-09 20:45 -0700
Re: String concatenation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-10 16:46 +1000
Re: String concatenation Paul Rubin <no.email@nospam.invalid> - 2016-05-10 00:13 -0700
Re: String concatenation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-10 17:54 +1000
Re: String concatenation David Palao <dpalao.python@gmail.com> - 2016-05-10 10:15 +0200
Re: String concatenation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-12 17:27 +1000
Re: String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) srinivas devaki <mr.eightnoteight@gmail.com> - 2016-05-09 09:01 +0530
Re: String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) srinivas devaki <mr.eightnoteight@gmail.com> - 2016-05-09 09:13 +0530
Re: String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) Michael Selik <michael.selik@gmail.com> - 2016-05-09 18:29 +0000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 19:53 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-11 02:16 +0200
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 20:33 -0400
Moderation [was Re: ...What's wrong with this concatenation statement?] Steven D'Aprano <steve@pearwood.info> - 2016-05-11 11:17 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Chris Angelico <rosuav@gmail.com> - 2016-05-11 11:43 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-11 21:12 +0200
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Ned Batchelder <ned@nedbatchelder.com> - 2016-05-11 12:39 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Chris Angelico <rosuav@gmail.com> - 2016-05-12 09:07 +1000
Re: % formatting vs .format() (was: What's wrong with this concatenation statement?) Tim Chase <python.list@tim.thechases.com> - 2016-05-11 18:31 -0500
Re: String concatenation (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) sohcahtoa82@gmail.com - 2016-05-10 17:38 -0700
Re: String concatenation Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-11 21:14 +0200
Re: String concatenation sohcahtoa82@gmail.com - 2016-05-11 14:30 -0700
Re: String concatenation Ned Batchelder <ned@nedbatchelder.com> - 2016-05-11 14:50 -0700
Re: String concatenation DFS <nospam@dfs.com> - 2016-05-11 18:25 -0400
Re: What's wrong with this concatenation statement? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-05-09 17:53 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 12:16 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Rustom Mody <rustompmody@gmail.com> - 2016-05-10 09:41 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Stephen Hansen <me+python@ixokai.io> - 2016-05-10 09:42 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 18:37 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Steven D'Aprano <steve@pearwood.info> - 2016-05-11 02:44 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Ian Kelly <ian.g.kelly@gmail.com> - 2016-05-10 12:15 -0600
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 17:21 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Chris Angelico <rosuav@gmail.com> - 2016-05-11 07:27 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 19:40 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Paul Rubin <no.email@nospam.invalid> - 2016-05-10 19:14 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? alister <alister.ware@ntlworld.com> - 2016-05-12 09:12 +0000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Chris Angelico <rosuav@gmail.com> - 2016-05-12 19:23 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-12 08:24 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Michael Torrie <torriem@gmail.com> - 2016-05-12 08:39 -0600
Why online forums have bad behaviour (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) Ben Finney <ben+python@benfinney.id.au> - 2016-05-13 05:36 +1000
Re: Why online forums have bad behaviour (was: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement?) Jason Friedman <jsf80238@gmail.com> - 2016-05-12 21:05 -0600
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Ethan Furman <ethan@stoneleaf.us> - 2016-05-10 15:12 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 19:29 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2016-05-12 13:39 +0000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Chris Angelico <rosuav@gmail.com> - 2016-05-12 23:50 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Ethan Furman <ethan@stoneleaf.us> - 2016-05-10 16:16 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? DFS <nospam@dfs.com> - 2016-05-10 19:41 -0400
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? srinivas devaki <mr.eightnoteight@gmail.com> - 2016-05-12 13:53 +0530
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Ned Batchelder <ned@nedbatchelder.com> - 2016-05-12 02:36 -0700
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Steven D'Aprano <steve@pearwood.info> - 2016-05-13 01:06 +1000
Re: Steve D'Aprano, you're the "master". What's wrong with this concatenation statement? Chris Angelico <rosuav@gmail.com> - 2016-05-12 18:40 +1000
csiph-web