0

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?

1 Answer 1

1

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"].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.