Python Forum

Full Version: PyQt5: Iterate through rows to check for a value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am trying to use a for loop to check every row of a table for a certain value and then either add 1 or 0 to a list. I am currently trying:
            for row in range(rowPosition):
                item = self.invoice.item(row, 0)
                itemText = item.text()
                if itemText == "value being searched for":
                    test.append(1)

                else:
                    test.append(0)
            ##rowPosition is rowCount()
When i try this, it just fails, I did try the item function putting a certain row in and that works, but it will not use the row value.
Thanks in advance.
please show:
  • What type of file (csv, txt, or whatever)
  • code prior to for loop (a runnable snippet is best)
  • If you can, entire script
Don't worry, I got it working, I just had to set the range to 1, rowPosition.