473,396 Members | 2,092 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,396 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 1318
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.