.fetchone()
while ループを呼び出すだけでなく、次のジェネレーター関数を作成する利点はありますか? もしそうなら、その利点は何ですか?
ありがとう。
def testf2():
db = connectToMysqlDB(None)
sql_statement = " ".join([
"select d.* ",
"from dr_snapshot d ",
"order by d.PremiseID asc, d.last_read asc; "])
sel_cur = db.cursor()
rc = sel_cur.execute(sql_statement)
loop_ok = True
while loop_ok:
meter_row = sel_cur.fetchone()
if meter_row:
yield meter_row
else:
loop_ok = False
yield None
for read_val in testf2():
print(read_val)
#Perform something useful other than print.
('610159000', 6, datetime.datetime(2012, 7, 25, 23, 0), 431900L, 80598726L)
('610160000', 6, datetime.datetime(2012, 7, 25, 23, 0), 101200L, 80581200L)
None