path slashes cleaning

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mathieu Prevot

    path slashes cleaning

    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
  • Mike Driscoll

    #2
    Re: path slashes cleaning

    On Sep 4, 8:25 am, "Mathieu Prevot" <mathieu.pre... @gmail.comwrote :
    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

    Comment

    • Michael Wronna

      #3
      Re: path slashes cleaning

      Am 04.09.2008, 15:27 Uhr, schrieb Mike Driscoll <kyosohma@gmail .com>:
      On Sep 4, 8:25 am, "Mathieu Prevot" <mathieu.pre... @gmail.comwrote :
      >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
      Hi, how about
      a.rstrip('/')
      ? Michael

      Comment

      Working...