擅长:python、mysql、java
<p>您可以创建一个自定义包装,如:</p>
<pre><code>class Table(object):
def __init__(self, gp, table):
self.gp = gp
self.table = table
self.cursor = None
def __iter__(self):
self.cursor = self.gp.getcursor(self.table)
return self
def next(self):
n = self.cursor.next()
if not n:
raise StopIteration()
return n
</code></pre>
<p>然后:</p>
^{pr2}$
<p>另请参见:<a href="http://docs.python.org/library/stdtypes.html#typeiter" rel="nofollow noreferrer">Iterator Types</a></em></p>