split() and string.whitespace

Chris Rebert clp at rebertia.com
Fri Oct 31 15:02:46 EDT 2008


On Fri, Oct 31, 2008 at 11:53 AM, Chaim Krause <chaim at chaim.com> 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(' ')
> print mytext.split(whitespace)
> print string.split(mytext, sep=whitespace)

Also note that a plain 'mytext.split()' with no arguments will split
on any whitespace character like you're trying to do here.

Cheers,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

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



More information about the Python-list mailing list