Solved [bug?]One specific value run code piece twice
-
I'm new to python and pyqt(I'm using pycharm as IDE), so I don't know if this is a bug or is something wrong with my code?
I have a text file with greek words one at a line, with capital letters. I'm using QFile and QTextStream to check if the given word exists in this file. This is the piece of code:def checkWrd(self): correctWord="" datafile = QFile(":resources/dict/words.txt") if not datafile.open(QIODevice.ReadOnly | QIODevice.Text): return stream=QTextStream(datafile) stream.seek(0) while not datafile.atEnd(): line=stream.readLine() if len(self.MYWORD)>1 and line==self.MYWORD and not self.wordsList.findItems(line,Qt.MatchExactly): print(line) correctWord=correctWord+line datafile.close() return correctWord
This works fine except 1 specific word. I have tested a lot of times other different words and only on that I have this strange behaviour. The word is "ΤΙΣ"
I also checked this word in the text file and I replaced it myself with greek capital leters.
The problem is that the word changes to "ΤΙΣΤΙΣ" and also doesn't respect other restrictions, as to don't readded to the list.
I put 2 breakpoints in debugger on the lines:print(line) correctWord=correctWord+line
and Ι can see that on this specific word these to lines executed twice, so the result is "ΤΙΣΤΙΣ"
When I input the word and press the button to run the check method the program breaks to the first breakpoint. By pressing the debugger's "resume program" button, it breakes to the next break point.
In all other words i checked, after that it continues to the next code and the word appears correct.
But for that specific word, it jumbs again to the first breakpoint, and after to the second. So these to lines executed twice.
Any ideas why this happens? -
I answering myself because I think I found the issue. Seems that sothing was wrong with the file. And because I'm loading the file from the resources was needed to recompile the resources file for changes to the file to applied. I thought that the file read from its path, but seems that from resources is loading an instance of the file and not the file itself.
Anyway, seems that my issue solved.