Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 4:29 AM, Travis Griggs travisgri...@gmail.com wrote: if k + ‘_@‘ in documents: timeKey = k + ‘_@‘ historyKey = thingID + ‘_’ + k I’m curious where others lean stylistically with this kind of thing. I see *at least* 2 other alternatives: So few? I'd

Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 5:19 AM, Ben Bacarisse ben.use...@bsb.me.uk wrote: Chris Angelico ros...@gmail.com writes: On Fri, Apr 10, 2015 at 4:46 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: Travis Griggs travisgri...@gmail.com writes: Here’s 3 examples: if k + ‘_@‘ in documents:

Concatenating Strings

2015-04-09 Thread Travis Griggs
I was doing some maintenance now on a script of mine… I noticed that I compose strings in this little 54 line file multipole times using the + operator. I was prototyping at the time I wrote it and it was quick and easy. I don’t really care for the way they read. Here’s 3 examples: if k +

Re: Concatenating Strings

2015-04-09 Thread Andrew Farrell
I am under the impression that using format() is the canonically right way to do it. It is certainly more readable than using ''.join() and is more semantically specific than string addition. On Thu, Apr 9, 2015 at 1:35 PM, Chris Angelico ros...@gmail.com wrote: On Fri, Apr 10, 2015 at 4:29 AM,

Re: Concatenating Strings

2015-04-09 Thread Ben Bacarisse
Chris Angelico ros...@gmail.com writes: On Fri, Apr 10, 2015 at 4:46 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: Travis Griggs travisgri...@gmail.com writes: Here’s 3 examples: if k + ‘_@‘ in documents: timeKey = k + ‘_@‘ historyKey = thingID + ‘_’ + k In addition

Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 4:46 AM, Ben Finney ben+pyt...@benfinney.id.au wrote: Travis Griggs travisgri...@gmail.com writes: Here’s 3 examples: if k + ‘_@‘ in documents: timeKey = k + ‘_@‘ historyKey = thingID + ‘_’ + k In addition to the other responses, I'll point out a

Re: Concatenating Strings

2015-04-09 Thread Ben Finney
Travis Griggs travisgri...@gmail.com writes: Here’s 3 examples: if k + ‘_@‘ in documents: timeKey = k + ‘_@‘ historyKey = thingID + ‘_’ + k In addition to the other responses, I'll point out a different issue: Your client is composing messages that munge your text. Ensure you

Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 4:44 AM, Andrew Farrell amfarr...@mit.edu wrote: I am under the impression that using format() is the canonically right way to do it. It is certainly more readable than using ''.join() and is more semantically specific than string addition. Depends what you're doing.

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-12-02 Thread Sworddragon
() : 0.032835 concatenate_string_join() : 0.170623 concatenate_string_and_encode(): 0.037280 - As we already know concatenating bytes is much slower then concatenating strings. - concatenate_bytearray() shows that doing this with bytearrays is 5 times slower than concatenating strings. Also

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-12-02 Thread R. David Murray
R. David Murray added the comment: Please take these observations and questions to python-list. They aren't really appropriate for the bug tracker. We aren't going to add the optimization shortcut for bytes unless someone does a bunch of convincing on python-ideas, which seems unlikely (but

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-12-02 Thread Sworddragon
Sworddragon added the comment: We aren't going to add the optimization shortcut for bytes There is still the question: Why isn't this going to be optimized? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19801

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-11-26 Thread Sworddragon
files: test.py messages: 204503 nosy: Sworddragon priority: normal severity: normal status: open title: Concatenating bytes is much slower than concatenating strings type: behavior versions: Python 3.3 Added file: http://bugs.python.org/file32859/test.py

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-11-26 Thread R. David Murray
R. David Murray added the comment: It is definitely not a good idea to rely on that optimization of += for string. Obviously bytes doesn't have the same optimization. (String didn't either for a while in Python3, and there was some controversy around adding it back exactly because one

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-11-26 Thread R. David Murray
Changes by R. David Murray rdmur...@bitdance.com: -- type: behavior - performance ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19801 ___ ___

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-11-26 Thread Antoine Pitrou
Antoine Pitrou added the comment: Indeed. If you want to concatenate a lot of bytes objects efficiently, there are three solutions: - concatenate to a bytearray - write to a io.BytesIO object - use b''.join to concatenate all objects at once -- nosy: +pitrou

[issue19801] Concatenating bytes is much slower than concatenating strings

2013-11-26 Thread Benjamin Peterson
Changes by Benjamin Peterson benja...@python.org: -- resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue19801 ___

concatenating strings

2006-12-15 Thread EHC
hello! since i am a py noob, please bear with me ; ) how is it possible to concat a string and an integer in a print-command? i've tried print This robot is named %s. The current speed setting is %d, and %s has a lifetime of %d % (self.name , self.speed , self.name) as well as print This

Re: concatenating strings

2006-12-15 Thread Laurent Pointal
EHC a écrit : hello! since i am a py noob, please bear with me ; ) how is it possible to concat a string and an integer in a print-command? i've tried print This robot is named %s. The current speed setting is %d, and %s has a lifetime of %d % (self.name , self.speed , self.name) Four

Re: concatenating strings

2006-12-15 Thread Erich Pul
thank you, i just plainly overlooked it ; ) now it works -- http://mail.python.org/mailman/listinfo/python-list

Re: concatenating strings

2006-12-15 Thread Caleb Hattingh
Hi Erich If you're going to be doing a lot of string substitution, you should look at the Templating support in the library: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/304005 and (a little bit fancier): http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/335308 Regards Caleb

Concatenating strings

2006-06-30 Thread John Henry
Sorry if this is a dumb question. I have a list of strings (some 10,000+) and I need to concatenate them together into one very long string. The obvious method would be, for example: alist=[ab,cd,ef,.,zzz] blist = for x in alist: blist += x But is there a cleaner and faster way of

Concatenating strings

2006-06-30 Thread John Henry
Sorry if this is a dumb question. I have a list of strings (some 10,000+) and I need to concatenate them together into one very long string. The obvious method would be, for example: alist=[ab,cd,ef,.,zzz] blist = for x in alist: blist += x But is there a cleaner and faster way of

Re: Concatenating strings

2006-06-30 Thread Robert Kern
John Henry wrote: Sorry if this is a dumb question. I have a list of strings (some 10,000+) and I need to concatenate them together into one very long string. The obvious method would be, for example: alist=[ab,cd,ef,.,zzz] blist = for x in alist: blist += x But is there a

Re: Concatenating strings

2006-06-30 Thread Steven Bethard
John Henry wrote: I have a list of strings (some 10,000+) and I need to concatenate them together into one very long string. The obvious method would be, for example: alist=[ab,cd,ef,.,zzz] blist = for x in alist: blist += x But is there a cleaner and faster way of doing this?