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

Rick Johnson rantingrickjohnson at gmail.com
Mon Dec 26 17:48:35 EST 2011


On Dec 26, 4:23 pm, Charles Hixson <charleshi... at earthlink.net> wrote:
> This doesn't cause a crash, but rather incorrect results.
>
> self.wordList    =    ["The", "quick", "brown", "fox", "carefully",
>                  "jumps", "over", "the", "lazy", "dog", "as", "it",
>                  "stealthily", "wends", "its", "way", "homewards", '\b.']
> for    i    in    range (len (self.wordList) ):
>     if    not isinstance(self.wordList[i], str):
>         self.wordList = ""
>    elif self.wordList[i] != "" and self.wordList[i][0] == "\b":
>         print ("0: wordList[", i, "] = \"", self.wordList[i], "\"", sep
> = "")
>         print ("0a: wordList[", i, "][1] = \"", self.wordList[i][1],
> "\"", sep = "")
>         tmp    =    self.wordList[i][1]             ## !! Kludge --
> remove tmp to see the error
>         self.wordList[i]    =    tmp + self.wordList[i][1:-1]  ## !!
> Kludge -- remove tmp + to see the error
>         print ("1: wordList[", i, "] = \"", self.wordList[i], "\"", sep
> = "")
>         print    ("len(wordList[", i, "]) = ", len(self.wordList[i]) )
>
> --
> Charles Hixson

Handy rules for reporting bugs:

1. Always format code properly.
2. Always trim excess fat from code.
3. Always include relative dependencies ("self.wordlist" is only valid
inside a class. In this case, change the code to a state that is NOT
dependent on a class definition.)

Most times after following these simple rules, you'll find egg on your
face BEFORE someone else has a chance to see it and ridicule you.



More information about the Python-list mailing list