Search code examples
pythonvariablespyqtincrementqlineedit

How to increment QLineEdit name to access value?


This seems like a really simple question, but has me stumped. I've got a UI that has multiple QLineEdits for names, start, and end times. For example:

clipName1, clipStart1, clipEnd1 clipName2, clipStart2, clipEnd2 clipName2, clipStart3, clipEnd3

These are not dynamically built on the fly. They are static. I wish to access the values from these by going through a loop. I am not sure how I can append an integer onto the variable name and still be able to access the value. I've tried this which I know doesn't work:

    clipTotal = 4

    for i in range(1, clipTotal+1):
        clipName = self.clipName+str(i)+.text()

Solution

  • Answer provided by ekhumoro in comments above:

    clipName = getattr(self, 'clipName%d' % i).text()