I just ran python and did the following:
-----------------------------------------------------------------------------
Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 'hel[lo]'
>>> a
'hel[lo]'
>>> a.strip("[")
'hel[lo]'
>>> a.strip("]")
'hel[lo'
>>> a.strip("\[")
'hel[lo]'
>>> b = "hel[lo]"
>>> b
'hel[lo]'
>>> b.strip("[")
'hel[lo]'
>>> b.strip("]")
'hel[lo'
>>> a='hel[lo]o'
>>> a.strip("[")
'hel[lo]o'
>>> a.strip("]")
'hel[lo]o'
>>> b="[hello]"
>>> b.strip("]")
'[hello'
>>> b.strip("[")
'hello]'
>>>
It appears strip only strips the first or last characters if they are the same
as the one passed in the function.
JK
--------------------------------------------------------
>Hello,
>For some reason Python refuses to strip a square bracket from a string:
>string = "[test]"
>string.strip("[") works fine
>string.strip("]") refuses to work
>If i do a test in IDLE it works fine!
>I must be missing something.
>Thanks,
>Oliver.
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!