2008/10/7 Justin Kelly <john.kelly at usa.net>:
> 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.
The first suggestion there is useful.
>>>> a = 'hel[lo]'
>>>> a
> 'hel[lo]'
>>>> a.strip("[")
> 'hel[lo]'
<snip>
>>>> 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.
Yes, that's what strip() does. More or less. (It doesn't limit itself
to one character.)
help("str")
will say exactly what "string".strip() does. I don't know how
discoverable that command is.
It will also show that perhaps what the OP wanted was something like
a.replace("[","")
>>I must be missing something.
>>>>Thanks,
>>Oliver.
Why did you try strip() and not trim() or delete() or tr-d()?
There's usually a fine manual somewhere to describe what the functions
really do. If there's a broken manual out there, it would be good to
get it fixed.
Good luck,
f
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!