[Python-ideas] PEP 428 - object-oriented filesystem paths
him at online.de
Tue Oct 9 16:58:49 CEST 2012
On 09/10/2012 16:30, Michele Lacchia wrote:
> > 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?
> Because the result would be (respectively): /path/foo/bar/ and
> In the second example the two strings would be concatenated and only
> then joined to the path.
> This is a very good argument against the + operator!
But why not interpret a path as a tuple (not a list, it's immutable) of
path segments and have:
path + ("foo", "bar")
path + ".tar.gz"
behave different (i.e. tuples add segments and strings add to the last
And of course path1 + path2 adds the segments together.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas