[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Wansoo Kim


Wansoo Kim  added the comment:

Well... to be honest, I'm a little confused. bpo-41244 and this issue are 
completely opposite. I'm not used to Python community yet because it hasn't 
been long since I joined it.

You're saying that if a particular method is not dramatically good, we prefer 
to keep the existing one as it is, right?

Your comment was very helpful to me. Maybe I can learn one by one like this.

Thank you very much.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

In this particular case the number of concatenations is limited, the resulting 
string is usually short, and the code is not performance critical (it is the 
__repr__ implementation). So there is no significant advantage of one way over 
other, and no way is obviously wrong. In such cases the status quo wins.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

Remi is correct.
Closing the issue.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
resolution:  -> wont fix
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Rémi Lapeyre

Rémi Lapeyre  added the comment:

Hi Wansoo, using += instead of str.join() is less performant. Concatenating n 
strings with + will create and allocate n new strings will str.join() will 
carefully look ahead and allocate the correct amount of memory and do all 
concatenation at one:


➜  ~ python3 -m timeit -s 's = ""' 'for i in range(1_000_000): s += "foo\n"'
5 loops, best of 5: 107 msec per loop
➜  ~ python3 -m timeit -s 'l = ["foo"]*1_000_000' '"\n".join(l)'
20 loops, best of 5: 9.96 msec per loop


It's a common idiom that you will meet a lot in Python.

--
nosy: +remi.lapeyre

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Wansoo Kim


Change by Wansoo Kim :


--
keywords: +patch
pull_requests: +20545
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/21397

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41242] When concating strings, I think it is better to use += than join the list

2020-07-08 Thread Wansoo Kim


New submission from Wansoo Kim :

Hello

I think it's better to use += than list.join() when concating strings.

This is more intuitive than other methods.

Also, I personally think it is not good for one variable to change to another 
type during runtime.

https://github.com/python/cpython/blob/b26a0db8ea2de3a8a8e4b40e69fc8642c7d7cb68/Lib/asyncio/base_events.py#L826

If you look at the link above, `msg` was a list type at first, in the end 
 become a str type.

--
components: asyncio
messages: 373310
nosy: asvetlov, ys19991, yselivanov
priority: normal
severity: normal
status: open
title: When concating strings, I think it is better to use += than join the list
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com