[Python-ideas] Add list.join() please
Terry Reedy
tjreedy at udel.edu
Wed Jan 30 02:17:29 EST 2019
On 1/29/2019 7:12 PM, MRAB wrote:
> 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.
I have done things like this in private code, but it makes for messy
signatures. The doc pretends that min has two signatures, given in the
docstring:
min(iterable, *[, default=obj, key=func]) -> value
min(arg1, arg2, *args, *[, key=func]) -> value
I believe that the actual signature is the uninformative min(*args,
**kwargs). The arg form, without key, is the original. If min were
being written today, I don't think it would be included.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list