whitespace

Geoff Gerrietts geoff at gerrietts.net
Fri Sep 19 19:48:18 EDT 2003


Quoting RR (rr84 at cornell.edu):
> Is there an easy way in python to remove whitespace from a string?

Depending on what you mean by "remove whitespace":

  >>> mystring = " a b c d e f g "
  >>> mystring.strip()
  'a b c d e f g'
  >>> import re
  >>> re.sub("\s+", "", mystring)    
  'abcdefg'


> -- 
> http://mail.python.org/mailman/listinfo/python-list

-- 
Geoff Gerrietts             "Whenever people agree with me I always 
<geoff at gerrietts net>     feel I must be wrong." --Oscar Wilde





More information about the Python-list mailing list