dudeja.rajat@gm ail.com wrote:
explicitly comparing against true is bad style; better write that as
if item.endswith(' \\'):
item.endswith(" \\") works just fine:
name\
'name\\'
True
.... print item[:-1]
....
name
instead of assuming that some builtin function is broken, try printing
the the value of item to check that it really contains what you think it
does. (use print repr(item) to see control characters etc).
</F>
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:
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:
if item.endswith(' \\'):
item = item[0:-1] # This one I googled and
found to remove the last character /
dirListFinal.ap pend(item)
else:
dirListFinal.ap pend(item)
>
>
item.endswith() does not seem to be working.
found to remove the last character /
dirListFinal.ap pend(item)
else:
dirListFinal.ap pend(item)
>
>
item.endswith() does not seem to be working.
>>item = "name\\"
>>print item
>>print item
>>print repr(item)
>>item.endswith ("\\")
>>if item.endswith(" \\") == True:
....
name
instead of assuming that some builtin function is broken, try printing
the the value of item to check that it really contains what you think it
does. (use print repr(item) to see control characters etc).
</F>