split() and string.whitespace

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Fri Oct 31 14:57:48 EDT 2008


On Fri, 31 Oct 2008 11:53:30 -0700, Chaim Krause wrote:

> I am unable to figure out why the first two statements work as I expect
> them to and the next two do not. Namely, the first two spit the sentence
> into its component words, while the latter two return the whole sentence
> entact.
> 
> import string
> from string import whitespace
> mytext = "The quick brown fox jumped over the lazy dog.\n"
> 
> print mytext.split()
> print mytext.split(' ')

This splits at the string ' '.

> print mytext.split(whitespace)

This splits at the string '\t\n\x0b\x0c\r ' which doesn't occur in 
`mytext`.  The argument is a string not a set of characters.

> print string.split(mytext, sep=whitespace)

Same here.

Ciao,
	Marc 'BlackJack' Rintsch




More information about the Python-list mailing list