Python Forum
PyQt5: Iterate through rows to check for a value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt5: Iterate through rows to check for a value
#1
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.
Reply
#2
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
Reply
#3
Don't worry, I got it working, I just had to set the range to 1, rowPosition.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 2,785 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  PyQt5: Add Variable Number of Rows to Layout Based on Python Dictionary kennybassett 2 4,710 Oct-02-2018, 02:05 PM
Last Post: Alfalfa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020