This is a continuation of my previous post on Python generators with SWIG. I've improved the code, added an iterator class so that the same generator method can be called multiple times concurrently, and added a couple of macros to allow easy instantiation of the SWIG code.
As an example of how this would be used, see an excerpt of a 2D diffusion input file that uses my mesh library:
for c in mesh.cells(): source[c] = max( math.cos( c.getCenter() / 2 * math.pi ) + math.cos( c.getCenter() / 2 * math.pi ), 0)
UPDATE 4/25/2011: my project that uses this file is now posted on github.