python - How to do while() the "pythonic way" -
i want this:
from django.db import connection cursor = connection.cursor() cursor.execute("pragma table_info(ventegroupee)") while row = cursor.fetchone(): print(row)
i this:
file "<input>", line 1 while row = cursor.fetchone(): ^ syntaxerror: invalid syntax
what "pythonic" way of doing this?
you don't have use while
loop @ all, because cursors iterable:
for row in cursor: print(row)
from "connections , cursors" section of django documentation:
connection , cursor implement standard python db-api described in pep 249 — except when comes transaction handling.
from mentioned pep 249:
cursor.next()
return next row executing sql statement using same semantics .fetchone()
cursor.__iter__()
return self make cursors compatible iteration protocol
Comments
Post a Comment