[Python-ideas] PEP 428 - object-oriented filesystem paths

Joachim König him at online.de
Tue Oct 9 10:18:10 CEST 2012


On 09/10/2012 00:47 Greg Ewing wrote:
> I'd prefer 'append', because
>
>    path.append("somedir", "file.txt")
>
> is pretty self-explanatory, whereas

As has already been stated by others, paths are immutable so using them
like lists is leading to confusion (and list's append() only wants one 
arg, so
extend() might be better in that case).

But paths could then be interpreted as tuples of "directory entries" 
instead.

So adding a path to a path would "join" them:

pathA + pathB

and in order to not always need a path object for pathB one could also write
the right argument of __add__ as a tuple of strings:

pathA + ("somedir", "file.txt")

One could also use "+" for adding to the last segment if it isn't a path 
object or a tuple:

pathA + ".tar.gz"

Joachim



More information about the Python-ideas mailing list