[PD-dev] pyext looper

Frank Barknecht fbar at footils.org
Fri Aug 12 20:43:12 CEST 2005


Hallo,
B. Bogart hat gesagt: // B. Bogart wrote:

> What I am trying to accomplish is more or less this:
> 
> for x in xrange(x_upper-x_lower):
>   for y in xrange(y_upper-y_lower):
>     for z in xrange(z_upper-z_lower):
>       self._outlet(1,x+x_lower)
>       self._outlet(2,y+y_lower)
>       self._outlet(3,z+z_lower)
> 
> All this does is step through each point in a 3D matrix of points, and
> output the coordinates of each point.

... 

> So I thought I would rewrite the script without sleep() and use an
> external metro to drive it.
> 
> Now I can't figure out how to write a function that I call over and over
> again that is identical to the above code-block except doing only one
> iteration at a time.

That's what generators do, available in Python since 2.3. For a quick
intro see: 
http://www.python.org/doc/2.3.5/whatsnew/section-generators.html

They can be a bit tricky to use, until you get your head around the
concept. 

Attached is a quick example. It is "similar" to your problem above,
but not doing the same thing, as you will see, but it should give you
the idea about how generators work.

Ciao
-- 
 Frank Barknecht                               _ ______footils.org__
             
          _ __latest track: "plak" @ http://footils.org/cms/show/44
-------------- next part --------------
A non-text attachment was scrubbed...
Name: generate.py
Type: text/x-python
Size: 807 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20050812/7a96002e/attachment.py>


More information about the Pd-dev mailing list