How to delete a last character from a string

dudeja.rajat at gmail.com dudeja.rajat at gmail.com
Fri Aug 29 15:02:36 EDT 2008


On Fri, Aug 29, 2008 at 7:59 PM,  <dudeja.rajat at gmail.com> wrote:
> On Fri, Aug 29, 2008 at 7:41 PM, Mike Driscoll <kyosohma at gmail.com> wrote:
>> On Aug 29, 1:28 pm, dudeja.ra... at gmail.com wrote:
>>> Sorry : Earlier mail had a typo in Subject line which might look
>>> in-appropriate to my friends
>>>
>>> Hi,
>>>
>>> I've a list some of whose elements with character \.
>>> I want to delete this last character from the elements that have this
>>> character set at their end,
>>>
>>> I have written a small program, unfortunately this does not work:
>>>
>>> dirListFinal = []
>>> for item in dirList:
>>>            print item
>>>            if item.endswith('\\') == True:
>>>                item = item[0:-1]         # This one I googled and
>>> found to remove the last character /
>>>                dirListFinal.append(item)
>>>            else:
>>>                dirListFinal.append(item)
>>>
>>> item.endswith() does not seem to be working.
>>>
>>> Please help
>>> --
>>> Regrads,
>>> Rajat
>>
>>
>> Try something like this:
>>
>>>>> x = 'test\\'
>>>>> if x.endswith('\\'):
>>                x = x[:-1]
>>
>> This works with Python 2.5.2 on Windows XP.
>>
>> Mike
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
>
> There is just a single \ at the end of every item. My list is as below:
> ['Results v1.0/', 'Results v1.1/']
>
> so,
>
> if x.endswith('\\'):
>
> is that correct?
>

Sorry Guys. I did rubbish here and bothered you guys.
I did not recognize that I need to check for / character and not \

Really very sorry. Working for the last 14 hrs, could not see this
properly. Its time I must go home and take rest.


Regards,
Rajat



More information about the Python-list mailing list