path slashes cleaning

M

Mathieu Prevot

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
 
M

Mike Driscoll

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
 
M

Michael Wronna

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top