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

Ethan Furman ethan at stoneleaf.us
Sat Oct 6 18:38:54 CEST 2012


Antoine Pitrou wrote:
> On Sat, 6 Oct 2012 16:40:49 +0400
> Oleg Broytman <phd at phdru.name> wrote:
>> On Sat, Oct 06, 2012 at 04:26:42PM +0400, Oleg Broytman <phd at phdru.name> wrote:
>>> newpath = path.with_drive('C:')
>>> newpath = path.with_name('newname')
>>> newpath = path.with_ext('.zip')
>>    BTW, I think having these three -- replacing drive, name and extension --
>> is enough.

I do not.


> What is the point of replacing the drive?

At my work we have identical path structures on several machines, and we 
sometimes move entire branches from one machine to another.  In those 
instances it is good to be able to change from one drive/mount/share to 
another.


> Replacing the name is already trivial: path.parent()[newname]

Or, if '/' is allowed, path.path/newname.

I can see the reasonableness of using indexing (to me, it sorta looks 
like a window onto the path ;) ), but I prefer other methods when 
possible (tender wrists -- arthritis sucks)

~Ethan~



More information about the Python-ideas mailing list