[Python-ideas] PEP 428 - object-oriented filesystem paths
Massimo Di Pierro
massimo.dipierro at gmail.com
Tue Oct 9 15:49:06 CEST 2012
On Oct 9, 2012, at 12:31 AM, Greg Ewing wrote:
> Massimo DiPierro wrote:
>> The + symbol means addition and union of disjoint sets. A path (including a fs path) is a set of links (for a fs path, a link is a folder name). Using the + symbols has a natural interpretation as concatenation of subpaths (sets) to for form a longer path (superset).
> A reason *not* to use '+' is that it would violate associativity
> in some cases, e.g.
> (path + "foo") + "bar"
> would not be the same as
> path + ("foo" + "bar")
I am missing something. Why not?
> Using '/', or any other operator not currently defined on strings,
> would prevent this mistake from occuring.
> A reason to want an operator is the symmetry of path concatenation.
> Symmetrical operations deserve a symmetrical syntax, and to achieve
> that in Python you need either an operator or a stand-alone function.
> A reason to prefer an operator over a function is associativity.
> It would be nice to be able to write
> path1 / path2 / path3
> and not have to think about the order in which the operations are
> being done.
> If '/' is considered too much of a stretch, how about '&'? It
> suggests a kind of addition or concatenation, and in fact is
> used for string concatenation in some other languages.
> Python-ideas mailing list
> Python-ideas at python.org
More information about the Python-ideas