The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Stripping
Discuss Stripping in the Python Programming forum on Dev Shed. Stripping Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 21st, 2004, 02:39 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Posts: 44
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|
Stripping
I'm a little bit confused with strip function in module STRING sometime it works sometime not.For example
Code:
>> a = 'myname/is'
>> print string.strip(a,'/')
>> myname/is
so what's wrong?
|

April 21st, 2004, 03:00 PM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: Houston, TX
Posts: 383
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
|
|
|
How is that not working?
|

April 21st, 2004, 05:12 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
Code:
>>> import string
>>> help(string.strip)
Help on function strip in module string:
strip(s, chars=None)
strip(s [,chars]) -> string
Return a copy of the string s with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead.
If chars is unicode, S will be converted to unicode before stripping.
>>> string.strip('myname/is', '/')
'myname/is'
>>> string.strip('///myname/is///', '/')
'myname/is'
>>>
Dave - The Developers' Coach
|

April 21st, 2004, 05:15 PM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
BTW, the functions in the string module are the old way of doing it. Unless your code needs to be backwards compatible with Python 1.5.2 and earlier, then the preferred way is to use the methods on the string object itself:
Code:
>>> '///myname/is///'.strip('/')
'myname/is'
>>>
Dave - The Developers' Coach
|

April 22nd, 2004, 02:58 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
If you want to replace all occurances of particular strings/chars then you should look at the replace() method - very handy, i seem to use it when ever i do any string manipulation.
Have fun,
Mark.
__________________
programming language development: www.netytan.com – Hula
|

April 22nd, 2004, 07:47 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Posts: 44
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
Quote: | Originally Posted by netytan If you want to replace all occurances of particular strings/chars then you should look at the replace() method - very handy, i seem to use it when ever i do any string manipulation.
Have fun,
Mark. |
Yeah that one is COOL .. screw strip function.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|