使用
with,此工具可让您创建一个临时游标,一旦返回上一个缩进级别,该游标将关闭。
from contextlib import closingwith closing( connection.cursor() ) as cursor: (indented) use the cursor(non-indented) cursor is closed.connection.close()

使用
with,此工具可让您创建一个临时游标,一旦返回上一个缩进级别,该游标将关闭。
from contextlib import closingwith closing( connection.cursor() ) as cursor: (indented) use the cursor(non-indented) cursor is closed.connection.close()