Possible bug in string handling (with kludgy work-around)

Chris Angelico rosuav at gmail.com
Mon Dec 26 17:44:59 EST 2011


On Tue, Dec 27, 2011 at 9:23 AM, Charles Hixson
<charleshixsn at earthlink.net> wrote:
> This doesn't cause a crash, but rather incorrect results.

You may need to be a bit clearer. What line of code (or what
expression)? What did you expect to see, and what did you see?

>From examining your code, I've come up with one most-likely scenario.
In Python, indexing is zero-based and, in effect, indexes the
boundaries between items rather than the items themselves. Referencing
string[-1] actually means asking for the boundary between the
second-last and last characters; using that as your end marker
actually trims off the last character. What you may want is simply:

self.wordList[i][1:]

which means "from character position 1 to the end of the string".

Hope that helps!

Chris Angelico



More information about the Python-list mailing list