473,320 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Re: path slashes cleaning

On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <ma************@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
Sep 4 '08 #1
1 1313
On Sep 4, 6:32*am, "Francesco Guerrieri" <f.guerri...@gmail.com>
wrote:
On Thu, Sep 4, 2008 at 3:25 PM, Mathieu Prevot <mathieu.pre...@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.
Sep 4 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob Cowie | last post by:
Hi, Given a string representing the path to a file, what is the best way to get at the filename? Does the OS module provide a function to parse the path? or is it acceptable to split the string...
12
by: Xah Lee | last post by:
Python Doc Problem Example Quote from: http://docs.python.org/lib/module-os.path.html ---------- split( path) Split the pathname path into a pair, (head, tail) where tail is the last...
12
by: cjw | last post by:
Pl help me with this simple question. I am using an array to store the file name, eg. char in = "filename.bmp"; How can I give the directory path with the file name?
60
by: Sandeep Sharma | last post by:
Right from the time the first edition of K&R was released, the advantages of using symbolic constants, as opposed to "magic numbers", has been emphasized ---- and for good reason. I don't dispute...
3
by: Randy | last post by:
Hello All, I'm getting a strange error when trying to perform a file upload. Here's the lines that uploads the file... sSaveLocation = Server.MapPath("PFPDocs") + "\\" + fileName;...
3
by: Blake McNeill | last post by:
How do you retrieve a file path which was stored in the Registry as a string without ending up with a string which has all the slashes escaped which make it useless for file IO? I can see the file...
8
by: kj | last post by:
How can a script know its absolute path? (__file__ only gives the path it was used to invoke the script.) Basically, I'm looking for the Python equivalent of Perl's FindBin. The point of all...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
5
by: Kyle Hayes | last post by:
Is there a way to use the 'r' in front of a variable instead of directly in front of a string? Or do I need to use a function to get all of the slashes automatically fixed? /thanks -Kyle
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.