path slashes cleaning

Jason Scheirer jason.scheirer at gmail.com
Thu Sep 4 17:57:13 CEST 2008


On Sep 4, 6:32 am, "Francesco Guerrieri" <f.guerri... at gmail.com>
wrote:
> On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <mathieu.pre... at gmail.com> wrote:
> > Hi,
>
> > for scripts that take arguments, I would like to remove the trailing
> > slash if it's present.
>
> > Is there something else than:
>
> > a='/usr/local/lib/'
> > if a[-1] == '/':
> >  a = list(a)
> >  a.pop()
> >  ''.join(a)
>
> > Thanks,
> > Mathieu
>
> a.rstrip('/') does the job.
>
> bye,
> Francesco

[1]: import os.path
[2]: os.path.normpath('/usr/bin')
'/usr/bin'
[3]: os.path.normpath('/usr/bin/')
'/usr/bin'

And on windows:
[1]: import os.path
[2]: os.path.normpath(r'c:\data')
'c:\\data'
[3]: os.path.normpath('c:\\data\\')
'c:\\data'

Use the functions provided in os.path.



More information about the Python-list mailing list