I am trying to remove all spaces/tabs/newlines in python 2.7 on Linux.
I wrote this, that should do the job:
myString="I want to Remove all white \t spaces, new lines \n and tabs \t" myString = myString.strip(' \n\t') print myString
I want to Remove all white spaces, new lines and tabs
It seems like a simple thing to do, yet I am missing here something. Should I be importing something?
str.split([sep[, maxsplit]]) with no
sepis not specified or is
None, a different splitting algorithm is applied: runs of consecutive whitespace are regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace.
>>> myString.split() ['I', 'want', 'to', 'Remove', 'all', 'white', 'spaces,', 'new', 'lines', 'and', 'tabs']
str.join on the returned list to get this output:
>>> ' '.join(myString.split()) 'I want to Remove all white spaces, new lines and tabs'