How to delete a last character from a string

dudeja.rajat at gmail.com dudeja.rajat at gmail.com
Fri Aug 29 16:00:54 EDT 2008


On Fri, Aug 29, 2008 at 8:37 PM, Steven D'Aprano
<steve at remove-this-cybersource.com.au> wrote:
> On Fri, 29 Aug 2008 14:46:53 -0400, Derek Martin wrote:
>
>> On Fri, Aug 29, 2008 at 07:28:40PM +0100, dudeja.rajat at gmail.com wrote:
>>> dirListFinal = []
>>> for item in dirList:
>>>            print item
>>>            if item.endswith('\\') == True:
>>
>>              if item[-1] == '\\':
>
> Which will fail badly if item is the empty string.
>
>
> Rajat, rather than trying to invent your own code to join directory
> paths, you should use the os.path module:
>
>>>> import os
>>>> os.path.join('/dir', 'x', 'y', 'z', 'file.txt')
> '/dir/x/y/z/file.txt'
>>>> os.path.split('/a/b/c/d/file.txt')
> ('/a/b/c/d', 'file.txt')
>
>
> --
> Steven
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Steven, Thanks so much.
I just found out that I unknowingly searching for something else i.e.
/ rather than \
Just corrected this mistake and fixed it.


-- 
Regrads,
Rajat



More information about the Python-list mailing list