newby question: Splitting a string - separator

Thomas Liesner t.liesner at
Thu Dec 8 19:24:44 CET 2005

Hi all,

i am having a textfile which contains a single string with names.
I want to split this string into its records an put them into a list.
In "normal" cases i would do something like:

> #!/usr/bin/python
> inp = open("file")
> data =
> names = data.split()
> inp.close()

The problem is, that the names contain spaces an the records are also
just seprarated by spaces. The only thing i can rely on, ist that the
recordseparator is always more than a single whitespace.

I thought of something like defining the separator for split() by using
 a regex for "more than one whitespace". RegEx for whitespace is \s, but
what would i use for "more than one"? \s+?


More information about the Python-list mailing list