[Tutor] Re: A simpler mousetrap
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
> eg .html is often seen. And on non Windows platforms loing
> are common.
> > > x=os.path.splitext(a)+'.bak'
Whereas this technique handles the different size extensions safely.
More information about the Tutor