0

I'm creating a Python app with PyQt Gui. Basically I have multiple LineEdits with variable names like

Line_1 = 'x'
Line_2 = 'y'
Line_3 = 'z'
...
Line_15 = '0'

I wan't to create a loop through them at once like

for i in range(1, 15):
    self.Line_{0}.format(i).setEnabled(False)

but i couldn't manage to do it

ggnoredo
  • 801
  • 1
  • 13
  • 33
  • a dictionary job? – Chris_Rands Mar 16 '17 at 09:38
  • i converted .ui file with pyuic to .py. All of the Line_X variables are created separately so at this point i don't know how i should convert them since i'm a beginner and i have almost 100 variables need to be enabled/disabled upon choice of the user – ggnoredo Mar 16 '17 at 09:43
  • Please continue with whatever tutorial you're using and pay special attention to the part about lists and other data structures. – TigerhawkT3 Mar 16 '17 at 09:44
  • 1
    @fuzunspm. `getattr(self, 'Line_{0}'.format(i)).setEnabled(False)`. – ekhumoro Mar 16 '17 at 15:39

1 Answers1

0

Stop using variable names with numbers on the end when you should be using a list or a dict for the job.

Duncan
  • 92,073
  • 11
  • 122
  • 156