[Python-ideas] Accept list in os.path.join

Andrew Barnert abarnert at yahoo.com
Tue Jul 29 11:12:28 CEST 2014


On Tuesday, July 29, 2014 1:14 AM, Todd <toddrjen at gmail.com> wrote:

>Currently, os.path.join joins strings specified in its arguments, with one string per argument.  
>
>On its own, that is not a problem.  However, it is inconsistent with str.join, which accepts only a list of strings.

No, str.join accepts any iterable of strings—including a string, which is an iterable of single-character strings. 

Not that you often intentionally pass a string to it, but you do very often pass a generator expression or other iterator, so treating lists specially for os.path.join to make it work more like str.join would just increase confusion, not reduce it.

Also, I don't know of anything else in Python that has special treatment for lists vs. other iterables. There are a few cases that have special treatment for _tuples_ (notably str.__mod__), but I don't think anyone wants to expand those, and I don't think it would make you happy here, either.


More information about the Python-ideas mailing list