程序挂起......我正确关闭连接/程序

时间:2017-05-22 13:17:38

标签: python pyodbc

我是pyodbc的新手。我写了一个简单的程序。我认为。该程序不会关闭/退出。当我运行它时,它会挂起,直到我手动中断程序。它输出数据。我写得对吗?

import pyodbc
import csv

conn = pyodbc.connect('DSN=connect;UID=gog;PWD=humbleb')
cursor2 = conn.cursor()
cursor2.execute("SELECT PTIME, PVALUE FROM HISTORY_TABLE WHERE POINT = 'POINT' AND PTIME> '2017-04-12' AND PTIME<'2017-04-13' AND HISTTYPE='AVG' AND PERIOD=1200")
i=1
sample = cursor2.fetchall()
for rows in sample:
    with open ('C:/directory/record{0}.csv'.format(i), 'w') as f:
        csv.writer(f).writerow(rows)
    i += 1


 cursor2.close()
 conn.close()

0 个答案:

没有答案