[Python-ideas] PEP 428 - object-oriented filesystem paths
Ryan D Hiebert
ryan at ryanhiebert.com
Tue Oct 9 19:48:09 CEST 2012
On Oct 9, 2012, at 10:11 AM, Eric V. Smith <eric at trueblade.com> wrote:
>>> 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",)
or
pathA + Path("file.txt")
Just like with any tuple, if you wish to add a new part, it must be a tuple (Path) first.
I'm not convinced that adding a string to a path should be allowed, but if not then we should probably throw a TypeError if its not a tuple or Path. That would leave the following method for appending a suffix:
path[:-1] + Path(path[-1] + '.tar.gz')
That's alot more verbose than the option to "add a string".
Ryan
More information about the Python-ideas
mailing list