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

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Oct 7 01:28:51 CEST 2012

Massimo DiPierro wrote:
> How about something along this lines:
> class Path(str):
 >    ...
> path = Path('/this/is/an/example.png')
> print path[-1] # example.png

Unfortunately, if you subclass from str, I don't think it will
be feasible to make indexing return pathname components, because
code that's treating it as a string will be expecting it to
index characters.

Similarly you can't make + mean path concatenation -- it must
remain ordinary string concatenation.


More information about the Python-ideas mailing list