Using functions to reduce code.

Alex Martelli aleaxit at yahoo.com
Tue Oct 17 14:58:52 EDT 2000


"joonas" <keisari_ at hotmail.com> wrote in message
news:39EC7F1C.3805E714 at hotmail.com...
> Can i use functions to reduce the amount of code in that repeating
> script.

Yes.

def doit(curvescontainer, multiplier):
    for curve in curvescontainer.curves:
        for pt in curve.points:
            pt.pt[1] = pt.pt[0] * multiplier

There is no need for your "update" step.  So...:

> for cukiertopyora in kiertopyora.curves:
>   ptskiertopyora= cukiertopyora.points
>   for pt in ptskiertopyora:
>     pt.pt[1]= pt.pt[0]*nopeuskiertopyora
>   cukiertopyora.points= ptskiertopyora # update

becomes
    doit(kiertopyora, nopeuskiertopyora)

and so on.


Alex






More information about the Python-list mailing list