python - Pypyodbc TabError:缩进中制表符和空格的不一致使用
问题描述
这是一个常见的问题,似乎在这里,但就我而言,我找不到答案。为什么这里说制表符和缩进的使用不一致
def exectute_SQL(): #This function executes SQL to pull counts from a table where it wasnt possible to get an excel
con = pypyodbc.connect(conn_str)
cur = con.cursor()
sql = "SELECT * FROM Elig_Own.DST_Report_Validation_Test" #WHERE ysn_active = '1'"
cur.execute(sql)
rows = cur.fetchall()
for row in rows:
strFnd = 0
strReportName = row[1]
strSrcName = row[2]
strDestName = row[3]
strFileName = row[4]
try:
for report in strReportName:
if report == 'STR_DB Load to SQL':
cur.execute("$result = SELECT TOP 1 COUNT(*) FROM Elig_Own.STR_DB GROUP BY LAST_UPDATED ORDER BY LAST_UPDATED DESC;")
cur.execute("INSERT INTO Elig_Own.DST_Report_Status_Test(TDate, Report, Records, Status) VALUES(CAST(GetDate() AS Date), 'STR_DB Load to SQL', ?, 'Passed')",(result))
con.commit()
except:
print("Couldnt execute script")
这是错误信息
C:\Users\cn192406\Documents\Programs>python File_Check_Dart_Functions.py
File "File_Check_Dart_Functions.py", line 73
cur.execute("$result = SELECT TOP 1 COUNT(*) FROM Elig_Own.STR_DB GROUP BY LAST_UPDATED ORDER BY LAST_UPDATED DESC;")
TabError:缩进中制表符和空格的使用不一致
解决方案
尝试这个:
def exectute_SQL(): # This function executes SQL to pull counts from a table where it wasnt possible to get an excel
con = pypyodbc.connect(conn_str)
cur = con.cursor()
sql = "SELECT * FROM Elig_Own.DST_Report_Validation_Test" # WHERE ysn_active = '1'"
cur.execute(sql)
rows = cur.fetchall()
for row in rows:
strFnd = 0
strReportName = row[1]
strSrcName = row[2]
strDestName = row[3]
strFileName = row[4]
try:
for report in strReportName:
if report == "STR_DB Load to SQL":
cur.execute(
"$result = SELECT TOP 1 COUNT(*) FROM Elig_Own.STR_DB GROUP BY LAST_UPDATED ORDER BY LAST_UPDATED DESC;"
)
cur.execute(
"INSERT INTO Elig_Own.DST_Report_Status_Test(TDate, Report, Records, Status) VALUES(CAST(GetDate() AS Date), 'STR_DB Load to SQL', ?, 'Passed')",
(result),
)
con.commit()
except Exception as e:
pass
推荐阅读
- laravel - 如何在 Laravel 中使用表单销毁记录并显示状态?
- haskell - 在 Haskell 中实现 Prim 算法
- kubernetes - 多次安装单个 Kubernetes 部署
- php - 使用一个键注册多个对象是最佳实践吗?
- ios - Swift:是否有更快、更灵敏的方式来为 UIView 实现不同的角半径?
- java - 卡车中最大单位的贪婪方法
- c - 加入气泡的算法
- mysql - MYSQL,这不断弹出错误 SQL 查询:MySQL 说:文档 #1054 - '字段列表'中的未知列 'id_D10'
- android-studio - 由于“getDay()”已被弃用,如何从 Date 对象中获取日期?
- flutter - 如何处理 google_sign_in on flutter for error NoSuchMethodError: The getter 'authentication' was called on null?