[Python-ideas] PEP 428 - object-oriented filesystem paths
Ryan D Hiebert
ryan at ryanhiebert.com
Tue Oct 9 01:06:25 CEST 2012
On Oct 8, 2012, at 3:47 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> I'd prefer 'append', because
>
> path.append("somedir", "file.txt")
+1
In so many ways, I see a path as a list of its components. Because of that, path.append and path.extend, with similar semantics to list.append and list.extend, makes a lot of sense to me.
When I think about a path as a list of components rather than as a string, the '+' operator starts to make sense for joins as well. I'm OK with using the '/' for path joining as well, because the parallel with list doesn't fit in this case, although I understand Massimo's objection to it. In very many ways, I like thinking of a path as a list (slicing, append, etc).
The fact that list.append doesn't return the new list has always bugged me, but if we were to use append and extend, they should mirror the semantics from list.
I'm much more inclined to think of path as a special list than as a special string.
Ryan
More information about the Python-ideas
mailing list