Hi thomas +,
What was supposed to be very simple task has ended up dissolving my brain and now I have no idea how to solve it so I'm asking on here.
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.
The catch is that I need to send out these messages with a variable delay between them. I tried using the thread example from pyext which works fine on all my machines but was crashing windows badly (I'm using this patch to control a serial control camera, and that camera only works on a particular windows machine at work.
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.
If someone has an abstraction or a solution to this I'd be happy to see it. Unfortunatly the camera is locked away in a room at the University that I can't access over the weekend, so I would need to try and get this to work in the next 2 hours. :(
Thanks in advance, B.
PS: obviously any until/counter based solution will be great as well, but I had trouble getting that logic to work for me as well.
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
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
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.
And now the version, which should do what you want.
Ciao