path slashes cleaning

Mike Driscoll kyosohma at gmail.com
Thu Sep 4 09:27:56 EDT 2008


On Sep 4, 8:25 am, "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

How about this:

if a[-1] == '/':
    a = a[:-1]

Mike



More information about the Python-list mailing list