Antoine Pitrou wrote:
On Fri, 5 Oct 2012 20:19:12 +0100 Paul Moore
wrote: A path can be joined with another using the ``__getitem__`` operator::
>>> p = PurePosixPath('foo') >>> p['bar'] PurePosixPath('foo/bar') >>> p[PurePosixPath('bar')] PurePosixPath('foo/bar') There is a risk that this is too "cute". However, it's probably better
On 5 October 2012 19:25, Antoine Pitrou
wrote: than overloading the '/' operator, and you do need something short. I think overloading '/' is ugly (dividing paths??).
But '/' is the normal path separator, so it's not dividing; and it certainly makes more sense than `%` with string interpolations. ;)
Someone else proposed overloading '+', which would be confusing since we need to be able to combine paths and regular strings, for ease of use. The point of using __getitem__ is that you get an error if you replace the Path object with a regular string by mistake:
PurePath('foo')['bar'] PurePosixPath('foo/bar') 'foo'['bar'] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: string indices must be integers
If you were to use the '+' operator instead, 'foo' + 'bar' would work but give you the wrong result.
I would rather use the `/` and `+` and risk the occasional wrong result. (And yes, I have spent time tracking bugs because of that wrong result when using my own Path module -- and I'd still rather make that trade-off.) ~Ethan~