[Python-au] strip function-ta

vector180 Vector180W@netscape.net
Wed, 29 Jan 2003 08:56:52 +1100


Thanks guys
a misunderstanding with interactive mode
i forgot to make it
st=st.strip("h")
i was only st.strip("h")
so it wasnt actually "saving" the new stripped string.

matt@null.net wrote:
> on 28/1/03 5:45 PM, Andrew Bennetts wrote:
> 
> 
>>On Tue, Jan 28, 2003 at 05:27:31PM +1100, vector180 wrote:
>>
>>>Having som eproblems with the strip function.
>>>Activestate Pythonwin.
>>>some doc seems to indicate you can set which characters you want striped
>>>from the ends.
>>>strip([chars])
>>>i was hopeing strip("h") would strip leading,trailing  h s for eg.
>>>I have tried various configurations i hope I just have the syntax wrong.
>>
>>If I recall correctly, this was introduced in Python 2.2... which version of
>>Python do you have?
> 
> 
> Maybe try giving us some actual code you are using - this gives me the
> correct result:
> 
> 
>>>>st = "hello there"
>>>>st.strip("h")
>>>
> 'ello there'
> 
> 
> Maybe you are expecting it to strip 'in-place' like list.sort() does?
> 
> Strings, like tuples are immutable - they cannot be changed.  To get
> effectively in-place stripping, try:
> 
> 
>>>>st = "hello there"
>>>>st = st.strip("h")
>>>>st
>>>
> 'ello there'
> 
> Of course, if you are using an older version of python (before the great
> types/classes re-unification) you will need to:
> 
> import string
> st = "hello world"
> st = string.strip(st, "h")
> 
> Good luck.
> 
> Matt.