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

MRAB python at mrabarnett.plus.com
Tue Jan 29 19:12:05 EST 2019


On 2019-01-29 23:30, Terry Reedy wrote:
> On 1/28/2019 8:40 PM, Jamesie Pic wrote:
> 
>   > 0. os.path.join takes *args
> 
> Since at least 1 path is required, the signature is join(path, *paths).
> I presume that this is the Python version of the Unix version of the
> system call that it wraps..  The hidden argument is os.sep.  It is
> equivalent to os.sep.join((path,)+paths) (though one would not write it
> this way).
> 
>> 1. str.join takes a list argument,
> 
> This premise behind the (repeated) request is a false.  str.joins
> arguments are a string (the joiner) and an *iterable of strings*, which
> is an abstract subclass of the abstract concept 'iterable'.  And only a
> small fraction of lists are lists of strings and therefore iterables of
> strings.
> 
One the examples given was writing:

 >>> '/'.join('some', 'path')

To me, this suggests that what the OP _really_ wants is for str.join to 
accept multiple arguments, much as os.path.join does.

I thought that there would be a problem with that because currently the 
single argument is an iterable, and you wouldn't want to iterate the 
first argument of '/'.join('some', 'path').

However, both min and max will accept either a single argument that's 
iterated over or multiple arguments that are not, so there's a precedent 
there.


More information about the Python-ideas mailing list