[Python-ideas] Add list.join() please

Eric V. Smith eric at trueblade.com
Wed Jan 30 05:24:08 EST 2019


On 1/30/2019 5:07 AM, Jamesie Pic wrote:
> On Wed, Jan 30, 2019 at 7:03 AM Robert Vanden Eynde
> <robertve92 at gmail.com> wrote:
>>>
>>> Raises an error. Why should:
>>>
>>> “”.join([2, “2”]) not raise an error as well?
>>
>> I agree
> 
> What do you think could be the developer intent when they do
> ",".join([2, "2']) ?
> 
> If the intent is clearly to assemble a string, as it looks like, then
> I don't find any disadvantage to automate this task for them.

Your examples show literals, but I literally (heh) never use str.join 
this way. I always pass it some variable. And 100% of the time, if that 
variable (say it's a list) contains something that's not a string, I 
want it to raise an exception. I do not want this to succeed:

lst = ['hello', None]
', '.join(lst)

lst is usually computed a long way from where the join happens.

So, I do not want this task automated for me.

Eric


More information about the Python-ideas mailing list