string.split

Tom Harris TomH at optiscan.com
Wed Sep 5 02:18:32 EDT 2001


Hi,

The useful split() function in the string module by default splits on
whitespace, which is any combination of spaces, tabs, newlines, and possibly
other stuff. So I see the following behaviour:

>>> import string
>>> s = 'asa   \n  bb cc\n\tdd'
>>> string.split(s)
['asa', 'bb', 'cc', 'dd']

However the defaulted second argument to string.split() can only be used to
set a literal string that is the seperator. How do I split on any or all
occurrences of (for example) whitespace and a comma, without using regexes.
I mean string.split() must be able to do it anyway to achieve the default
behaviour. 

Tom Harris, Software Engineer
Optiscan Imaging, 15-17 Normanby Rd, Notting Hill, Melbourne, Vic 3168,
Australia
email tomh at optiscan.com     ph +61 3 9538 3333  fax +61 3 9562 7742

This email may contain confidential information. If you have received this
email in error, please delete it immediately,and inform us of the mistake by
return email. Any form of reproduction, or further dissemination of this
email is strictly prohibited. Also, please note that opinions expressed in
this email are those of the author, and are not necessarily those of
Optiscan Pty Ltd.







More information about the Python-list mailing list