Using functions to reduce code.
Calvelo Daniel
dcalvelo at pharion.univ-lille2.fr
Tue Oct 17 14:09:14 EDT 2000
joonas <keisari_ at hotmail.com> wrote:
: Can i use functions to reduce the amount of code in that repeating
: script.
:
: for cukiertopyora in kiertopyora.curves:
: ptskiertopyora= cukiertopyora.points
: for pt in ptskiertopyora:
: pt.pt[1]= pt.pt[0]*nopeuskiertopyora
: cukiertopyora.points= ptskiertopyora # update
:
: for cuensio in ensio.curves:
: ptsensio= cuensio.points
: for pt in ptsensio:
: pt.pt[1]= pt.pt[0]*nopeusensio
: cuensio.points= ptsensio # update
[ And another two along similar lines]
The structure that repeats is
for each_curve in a_set.curves:
for each_point in each_curve:
each_point.pt[0] = each_point.pt[1] * update_value_for_the_set
You may go along the lines of
for a_set, update_value in ( (kiertopyora, nopeuskiertopyora),
(ensio,nopeusensio),
(toisio,nopeustoisio),
(vihrea,nopeusvihrea) ):
for curve in a_set.curves:
for pt in curve.points:
pt.pt[1]= pt.pt[0] * update_value
Not knowing the exact structures you have, I removed the temp variables,
which may be useless.
Keep in mind that python's variables are dynamic references.
HTH, DCA
-- Daniel Calvelo Aros
calvelo at lifl.fr
More information about the Python-list
mailing list