[ILUG] Python strip "]" from string

Andrew McGill glug at lunch.za.net
Tue Oct 7 18:31:30 IST 2008


On Tuesday 07 October 2008 18:56:01 ollie at eillo.org wrote:
> 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
When it refuses to work, what does it do?

It works for me (TM):

# cat x.py
string = "[test]"
print string.strip("[")
print string.strip("]")

# python x.py
test]
[test

> If i do a test in IDLE it works fine!
You might have some strange UTF-8 in your source file that looks right, but 
isn't what you think it is.



More information about the ILUG mailing list