Hi,

 

I am refactoring my code.  I am trying to reduce the amount of lines by using more loops.  I tend to use copy and paste a lot instead of writing a loop to do the work.

 

For example, I have 30 textentry boxes numbered from entry20 to entry50.  I have used the following code to assign the entryboxes to a local name.

 

text20 = self.wTree.get_widget("entry20")

text21 = self.wTree.get_widget("entry21")

 

I have had a go at writing a loop for the above 30 textentry boxes.  It is below, but it does not work. 

 

for x in range(20,51):

            ent = "entry%s" % (str(x))

                   

            text_x = self.wTree.get_widget(ent)

 

Is it possible to do what I want it to do?  Am I on the right lines?  Any help or advice would be greatly appreciated.

 

Thanks,

 

John.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to