On 22 Jul 2006, [EMAIL PROTECTED] wrote: > > On Sat, 2006-07-22 at 14:11 +0100, John CORRY wrote: >> 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? > > NO. You are looking to create local variables "on the fly". But there > is a simple solution that accomplishes what you really want.
The "no" is not absolutely right IMO. He could write directly in the dictionary he gets when he calls locals() (but I think you're right in saying that this is only seldom a good idea). Karl -- Please do *not* send copies of replies to me. I read the list _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor