[Python-ideas] PEP 428 - object-oriented filesystem paths
Antoine Pitrou
solipsis at pitrou.net
Sat Oct 6 14:09:24 CEST 2012
On Fri, 5 Oct 2012 23:16:55 -0600
Eric Snow <ericsnowcurrently at gmail.com>
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:
The concrete Path objects' replace() method already maps to
os.replace().
Note os.replace() is new in 3.3 and is a portable always-overwriting
alternative to os.rename():
http://docs.python.org/dev/library/os.html#os.replace
Regards
Antoine.
--
Software development and contracting: http://pro.pitrou.net
More information about the Python-ideas
mailing list