【问题标题】:Pypyodbc TabError: inconsistent use of tabs and spaces in indentationPypyodbc TabError:缩进中制表符和空格的不一致使用
【发布时间】:2020-01-23 18:39:01
【问题描述】:

这似乎是一个常见问题,但就我而言,我找不到答案。为什么这里说制表符和缩进的使用不一致

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: 缩进中制表符和空格的使用不一致

【问题讨论】:

    标签: python pypyodbc


    【解决方案1】:

    试试这个:

    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
    
    

    【讨论】:

    • 还是同样的错误。我有一个例外,只是忘记将它包含在代码片段中
    • @BenSmith 尝试从这里复制粘贴我的代码。您的代码中可能混有制表符和空格。您应该始终使用制表符进行缩进或始终使用空格。您应该将编辑器配置为始终用空格替换制表符,反之亦然。
    猜你喜欢
    • 2015-08-28
    • 2019-04-15
    • 2019-07-24
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 2019-10-05
    • 1970-01-01
    相关资源
    最近更新 更多