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

Guido van Rossum guido at python.org
Tue Oct 9 19:44:27 CEST 2012


On Tue, Oct 9, 2012 at 10:11 AM, Eric V. Smith <eric at trueblade.com> wrote:
> 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",)
>
> right?
>
> That doesn't seem very friendly.

Yeah, like the problem with % formatting. Another argument for picking
a method name.

-- 
--Guido van Rossum (python.org/~guido)



More information about the Python-ideas mailing list