On 30/03/2012 18:28, Joel Goldstick wrote:
On Fri, Mar 30, 2012 at 1:25 PM, Joel Goldstick
<joel.goldst...@gmail.com>  wrote:
On Fri, Mar 30, 2012 at 1:09 PM, leam hall<leamh...@gmail.com>  wrote:
Python 2.4.3 on Red Hat 5. Trying to use strip to remove characters
but it doesn't seem to work like I thought.


res = subprocess.Popen(['uname', '-a'], stdout=subprocess.PIPE)
uname = res.stdout.read().strip()

uname
'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011
i686 i686 i386 GNU/Linux'

uname.strip(':')
'Linux myserver 2.6.18-274.el5PAE #1 SMP Fri Jul 8 17:59:09 EDT 2011
i686 i686 i386 GNU/Linux'

'www.example.com'.strip('cmowz.')
'example'

Thoughts?

Leam
--
Mind on a Mission<http://leamhall.blogspot.com/>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

str.strip() removes characters from begining and end of the string --
Not any in between.  Notice

example = "www.example.com".strip("wcomx")
example
'.example.'


The x remains


You could do list comprehension

n = "".join([x for x in "this has : some : colons" if x not in ':'])
n
'this has  some  colons'


Yuck :(

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> "this has : some : colons".replace(':', '')
'this has  some  colons'

--
Cheers.

Mark Lawrence.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to