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

Eric V. Smith eric at trueblade.com
Tue Oct 9 19:11:48 CEST 2012

On 10/09/2012 12:59 PM, Ryan D Hiebert wrote:
> On Oct 9, 2012, at 1:18 AM, Joachim König <him at online.de> wrote:
>> 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")
> I like it. As you pointed out, my comparison with list is inappropriate because of path's immutability. So .append() and .extend() probably don't make sense.
>> One could also use "+" for adding to the last segment if it isn't a path object or a tuple:
>> pathA + ".tar.gz"

But then you'd have to say:

pathA + ("file.txt",)


That doesn't seem very friendly.


More information about the Python-ideas mailing list