[Python-ideas] PEP 428 - object-oriented filesystem paths
Stephen J. Turnbull
stephen at xemacs.org
Sat Oct 6 10:04:44 CEST 2012
More information about the Python-ideas mailing list
Sat Oct 6 10:04:44 CEST 2012
- Previous message: [Python-ideas] PEP 428 - object-oriented filesystem paths
- Next message: [Python-ideas] PEP 428 - object-oriented filesystem paths
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Ethan Furman writes: > Eric Snow wrote: > > On Fri, Oct 5, 2012 at 5:48 PM, Antoine Pitrou <solipsis at pitrou.net> wrote: > >> On Fri, 05 Oct 2012 14:38:57 -0700 > >> Ethan Furman <ethan at stoneleaf.us> wrote: > >>> Say I have a .dbf table as PureNTPath('c:\orders\12345\abc67890.dbf'), > >>> and I export it to .csv in the same folder; how would I transform the > >>> above PureNTPath's ext from 'dbf' to 'csv'? > >> Something like: > >> > >>>>> p = PureNTPath('c:/orders/12345/abc67890.dbf') > >>>>> p.parent()[p.name.split('.')[0] + '.csv'] > >> PureNTPath('c:\\orders\\12345\\abc67890.csv') > >> > >> Any suggestion to ease this use case a bit? > > > > 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') > > +1 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.
- Previous message: [Python-ideas] PEP 428 - object-oriented filesystem paths
- Next message: [Python-ideas] PEP 428 - object-oriented filesystem paths
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list