Tokenize

K

Ken Fettig

Does Python have an equivelent to the Java StringTokenizer? If so, what is
it and how do you implement it?
Thanks
Ken Fettig
(e-mail address removed)
(e-mail address removed)
 
A

Alan Kennedy

Ken said:
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.
['This', 'is', 'a', 'string', 'to', 'be', 'tokenised']
['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?
 
A

Andrew Dalke

Ken Fetting wants a 'StringTokenizer'.

Alan Kennedy points out
['This', 'is', 'a', 'string', 'to', 'be', 'tokenised'] ...
Or maybe you have something more specific in mind?

Another option is the little-known 'shlex' module, part of the standard
library.

As you can see, it treats '-' unexpectedly (compared to the shell).
Also, with __iter__ in newer Pythons, if these module were useful
then it would be nice if "for token in shlex..." worked.

Andrew
(e-mail address removed)
 
H

Harry George

Ken Fettig said:
Does Python have an equivelent to the Java StringTokenizer? If so, what is
it and how do you implement it?
Thanks
Ken Fettig
(e-mail address removed)
(e-mail address removed)

See shlex (in the main distribution) or see a variety of lexer/parser
tools such as Ply, Yapp.py,

shlex is about the level of complexity you want. See the Library
Reference Manual for instructions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top