strip not working on strings?

D

dan.j.weber

I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:
'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do. Thanks for any help.
 
M

marduk

I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:

'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do. Thanks for any help.

According to my docs it says "Return a copy of the string with the
leading and trailing characters removed." There are no leading or
trailing spaces or colons in 'p p:p'.

What your probably looking for is the .replace() method.

-m
 
P

Pierre Quentel

(e-mail address removed) a écrit :
I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:



'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do. Thanks for any help.

strip(chars) "returns a copy of the string with leading and trailing
characters removed", that is, at the beginning and at the end of the string

You can use this to remove the specified characters :

for char in chars:
s.replace(char,'')

Pierre
 
E

Eric Jacoboni

I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:

'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do.

In /my/ docs, s.strip return a copy of s where all /leading/ and
/heading/ spaces are removed. s.strip(x) does the same but removing
chars of x.

So, what you're asking for by s.strip(' :') is "remove heading or
leading space or ':' chars", /not/ "remove heading or leading space or
':' chars".

If you want to get rid of ' ' and ':' anywhere in s, i think that
string.maketrans and s.translate will do the job:
'ppp'
 
E

Eric Jacoboni

I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:

'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do.

In /my/ docs, s.strip return a copy of s where all /leading/ and
/heading/ spaces are removed. s.strip(x) does the same but removing
chars of x.

So, what you're asking for by s.strip(' :') is "remove heading or
leading space or ':' chars", /not/ "remove or leading or
':' chars".

If you want to get rid of ' ' and ':' anywhere in s, i think that
string.maketrans and s.translate will do the job:
'ppp'
 
E

Eric Jacoboni

I'm using Python 2.3.5 and when I type the following in the interactive
prompt I see that strip() is not working as advertised:

'p p:p'

Is this just me or does it not work? I want to get rid of all ' ' and
':' in the string. I've checked the doc and from what I can tell this
is what strip() is supposed to do.

In /my/ docs, s.strip return a copy of s where all /leading/ and
/heading/ spaces are removed. s.strip(x) does the same but removing
chars of x.

So, what you're asking for by s.strip(' :') is "remove heading or
leading space or ':' chars", /not/ "remove space or
':' chars".

If you want to get rid of ' ' and ':' anywhere in s, i think that
string.maketrans and s.translate will do the job:
'ppp'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top