[Tutor] Issues with tokenizing a string

Vicki Stanfield vicki at thepenguin.org
Thu Aug 21 15:25:26 EDT 2003


I am trying to tokenize a string and then test on the values of the
tokens, some of which might be empty. The situation is such that I have to
retrieve data from a combobox dropdown and from a wxTextCtrl window if
populated with data. The wxTextCtrl will contain zero to several
space-delimited "tokens".

self.arguments = self.parameters.GetValue()
is what I use to read the string to tokenize. I get a string like:
"1 F 4"

I then try to tokenize the string with:
       if arguments:
            parameters=self.arguments.split(" ")
            x=0
            while parameters != "":
                outfile.write(parameters[x])
                print parameters[x]
                x=x+1
        else: parameters = ""

It doesn't seem to like parameters[x] very much, telling me that the list
index is out of range. If I substitute a '0', it works fine.

Also, I am not sure what to use to determine the end of the arguments. If
it is read in from a wxTextCtrl, is it terminated in a "\n" or what?

--vicki



More information about the Tutor mailing list