Alan Kennedy alanmk at
Thu Jul 24 21:24:07 CEST 2003

Ken Fettig wrote:

> Does Python have an equivelent to the Java StringTokenizer? If so,
> what is it and how do you implement it?

Is this the kind of thing that you mean?

Python 2.3b1 (#40, Apr 25 2003, 19:06:24)
Type "help", "copyright", "credits" or "license" for more information.

>>> s = "This is a string to be tokenised"
>>> s.split()
['This', 'is', 'a', 'string', 'to', 'be', 'tokenised']

>>> s = "This:is:a:string:to:be:tokenised"
>>> s.split(':')
['This', 'is', 'a', 'string', 'to', 'be', 'tokenised']

>>> s.split(':', 2)
['This', 'is', 'a:string:to:be:tokenised']

Or maybe you have something more specific in mind?

alan kennedy
check http headers here:
email alan:    

More information about the Python-list mailing list