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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -