split() and string.whitespace
steve at REMOVE-THIS-cybersource.com.au
Sat Nov 1 01:23:47 CET 2008
On Fri, 31 Oct 2008 12:18:32 -0700, Chaim Krause wrote:
> I have arrived here while attempting to break down a larger problem. I
> got to this question when attempting to split a line on any whitespace
> character so that I could then add several other characters like ';' and
> ':'. Ultimately splitting a line on any char in a union of
> string.whitespace and some pre-designated chars.
> I am now beginning to think that I have outgrown split() and must move
> up to regular expressions. If that is the case, I will go off and RTFM
> on RegEx.
Or just do this:
s = "the quick brown\tdog\njumps over\r\n\t the lazy dog"
s = s.replace('\t', ' ').replace('\n', ' ').replace('\r', ' ')
or even simpler:
More information about the Python-list