[Tutor] Re: A simpler mousetrap

Alan Gauld alan.gauld at freenet.co.uk
Sun Dec 19 09:42:37 CET 2004


Rats, a premature posting sorry.

> > Also, just as interesting, yet probably less reliable:
> >
> > a = list(a)
> > a[-3:] = 'bak'
> > a = "".join(a)
>
>
> The problem with all of these versions is they assume the
> extension will be three characters long. In DOS it could be *up to*
> three characters, but in Windows post 95 the extension can be
longer,
> eg .html is often seen. And on non Windows platforms loing
extensions
> are common.

> > > x=os.path.splitext(a)[0]+'.bak'

Whereas this technique handles the different size extensions safely.

Alan G.



More information about the Tutor mailing list