[Python-ideas] PEP 428 - object-oriented filesystem paths

Andrew Svetlov andrew.svetlov at gmail.com
Fri Oct 5 22:59:24 CEST 2012


+1 in general. I like to have library like that in the battery.

I would to see the note why [] used instead  / or + in the pep while
I'm agree with that.
+0 for /
-1 for +
For method/property decision I guess (maybe stupid) rule:
properties for simple accessors and methods for operations which
require os calls.
With exception for parents() as method which returns generator.

On Fri, Oct 5, 2012 at 11:06 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Antoine Pitrou wrote:
>>
>> On Fri, 5 Oct 2012 20:19:12 +0100
>> Paul Moore <p.f.moore at gmail.com> wrote:
>>>
>>> On 5 October 2012 19:25, Antoine Pitrou <solipsis at pitrou.net> 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
>>> 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~
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas



-- 
Thanks,
Andrew Svetlov



More information about the Python-ideas mailing list