[Tutor] String Substitution

Daniel Ehrenberg littledanehren at yahoo.com
Sun Jan 18 22:31:17 EST 2004


> I only gave three controls as an example in fact
> there are 19 on this particular form. Others will
> have
> any number of them. Up to now I had just just
> being adding one control at a time as shown but
> decided that it cannot be very good scripting to do
> it this way especially with 19 controls and multiple
> forms. This is why I was trying to use the loop.
> 
> So the new question is, should I be sticking with
> one line per control, or if a loop is the way to go
> how do
> I do this if using 'eval' is not efficient. (but
> does work).
> 
> Thanks for help so far,
> 
> Richard  

If you have 19 controls, you should definitely use the
eval solution. If you're already using Python, then
you're valueing less code over efficiency (with
something like C). The speed penalty in this case is
negligible, but in general, use of eval is
discourgaged. A different version with (practically)
no speed penalty, using getattr(), would be

values.append(getattr(self,
'textCtrl%d'%i).GetValue())

Instead of evaluating the whole thing, this uses a
more specific (and therefore faster) mechanism to get
that item from self, and then normal code is used
GetValue(), so it is at full speed.

Daniel Ehrenberg

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus



More information about the Tutor mailing list