Creating an iterator in a class

TommyVee xxxxxxxx at
Thu Dec 27 16:34:13 CET 2012

"Joseph L. Casale"  wrote in message 
news:mailman.1346.1356619576.29569.python-list at

I am writing a class to provide a db backed configuration for an 

In my programs code, I import the class and pass the ODBC params to the
class for its __init__ to instantiate a connection.

I would like to create a function to generically access a table and provide 
iterator. How does one create a function in a class that takes an argument 
returns an iterator? I saw some examples where the class gets instantiated
with the table defined but I was hoping not to do this so I could continue 
access various tables through one connection/cursor.


Python makes it easy.  Read up on "Generators", and the "yield" statement. 
Works very elegantly with a "for ... in" loop.

More information about the Python-list mailing list