LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Python strip "]" from string

[ILUG] Python strip "]" from string

Francis Daly francisdaly at gmail.com
Wed Oct 8 01:33:22 IST 2008


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



More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


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!
RSS Version
Powered by Dell