0

I would like to know if there is a way to turn this into a for loop so it looks better.

print(self.User_Edit_1.text())
print(self.User_Edit_2.text())
print(self.User_Edit_3.text())
print(self.User_Edit_4.text())
print(self.User_Edit_5.text())
print(self.User_Edit_6.text())
print(self.User_Edit_7.text())

I want it to look something like this:

for i in range(1,8):
    print(self.User_Edit_{i}.text())

I have tried with an f string but it does not allow nested variables I don't think, I could turn it into a string, change the index, and then change it back to that kind of object, but I do not know how.

The class of the object is PyQt5.QtWidgets.QLineEdit, I am making a GUI.

On a related note, are their any current tutorials about PyQT5, the ones I have seen are from pyqt4 from 2015 and they do not work anymore and the docs seem rather confusing to use (I have tried)

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Ben_Ex
  • 55
  • 5

1 Answers1

0

You can put the items to iterate over in a collection of some sort such as a list:

user_list = [self.User_Edit_1, self.User_Edit_2, self.User_Edit_3, self.User_Edit_4, self.User_Edit_5, self.User_Edit_6, self.User_Edit_7]

for user in user_list:
    print(user.text())
grantslape
  • 95
  • 6