[Python-ideas] PEP 428 - object-oriented filesystem paths
Ethan Furman
ethan at stoneleaf.us
Sat Oct 6 20:44:02 CEST 2012
Oleg Broytman wrote:
> On Sat, Oct 06, 2012 at 05:04:44PM +0900, "Stephen J. Turnbull" <stephen at xemacs.org> wrote:
>> > Eric Snow wrote:
>> > > Each namedtuple has a _replace() method that's is used to generate a
>> > > new instance with one or more attributes changed. We could do
>> > > something similar here:
>> > >
>> > >>>> p = PureNTPath('c:/orders/12345/abc67890.dbf')
>> > >>>> p.replace(ext='.csv')
>> > > PureNTPath('c:\\orders\\12345\\abc67890.csv')
>>
>> How about a more general subst() method? Indeed, it would need
>> keyword arguments for named components like ext, but I often do things
>> like "mv ~/Maildir/{tmp,new}/42" in the shell. I think it would be
>> useful to be able to replace any component of a path.
>
> I think this would be overgeneralization. IMO there is no need to
> replace parts beyond drive/name/extension. To "replace" root or path
> components just construct a new Path.
And if your new path is exactly the same as the old, /except/ for the
root? Are you suggesting something like:
--> p = PureNTPath('c:/orders/12345/abc67890.dbf')
--> q = '//another_machine/share' + p.parts() + p.filename
?
~Ethan~
More information about the Python-ideas
mailing list