Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何做而不;“肾盂道”;_Python - Fatal编程技术网

Python 如何做而不;“肾盂道”;

Python 如何做而不;“肾盂道”;,python,Python,我想这样做: from django.db import connection cursor = connection.cursor() cursor.execute("PRAGMA table_info(ventegroupee)") while row = cursor.fetchone(): print(row) 我明白了: File "<input>", line 1 while row = cursor.fetchone():

我想这样做:

from django.db import connection

cursor = connection.cursor()
cursor.execute("PRAGMA table_info(ventegroupee)")
while row = cursor.fetchone():
    print(row)
我明白了:

  File "<input>", line 1
    while row = cursor.fetchone():
              ^
SyntaxError: invalid syntax
文件“”,第1行
当row=cursor.fetchone()时:
^
SyntaxError:无效语法

“pythonic”的方法是什么?

在循环时根本不需要使用
,因为游标是可编辑的:

for row in cursor:
    print(row)
从的“连接和游标”部分:

连接和游标主要实现标准的Python DB-API PEP 249中所述-交易处理除外

从所提到的:

Cursor.next()

使用返回当前正在执行的SQL语句的下一行 语义与.fetchone()相同

光标。__iter__;()

返回self以使游标与迭代协议兼容

您可以使用以下选项:

您可以找到一个关于python中for循环的好教程:

for row in cursor:
  ...