Reputation: 101
Instead of doing this:
A = (self.findChild(QtWidgets.QLineEdit, 'A')).text() # Find the input
B = (self.findChild(QtWidgets.QLineEdit, 'B')).text()
C = (self.findChild(QtWidgets.QLineEdit, 'C')).text()
I want to do something like this:
for x in ['A', 'B', 'C']:
x = (self.findChild(QtWidgets.QLineEdit, 'x')).text()
How do you write more concise code?
Upvotes: 0
Views: 44
Reputation: 4629
You will have to store the results in a dictionary:
texts = {}
for key in ("A", "B", "C"):
texts[key] = (self.findChild(QtWidgets.QLineEdit, key)).text()
Afterwards you won't be able to use directly A
but texts["A"]
.
Upvotes: 1