Re: path slashes cleaning

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Francesco Guerrieri

    #1

    Re: path slashes cleaning

    On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <mathieu.prevot @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
    a.rstrip('/') does the job.

    bye,
    Francesco
  • Jason Scheirer

    #2
    Re: path slashes cleaning

    On Sep 4, 6:32 am, "Francesco Guerrieri" <f.guerri...@gm ail.com>
    wrote:
    On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <mathieu.pre... @gmail.com>wrot e:
    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.normpat h('/usr/bin')
    '/usr/bin'
    [3]: os.path.normpat h('/usr/bin/')
    '/usr/bin'

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

    Use the functions provided in os.path.

    Comment

    Working...