Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/344.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 PYODBC TabError:缩进中制表符和空格的使用不一致_Python_Pypyodbc - Fatal编程技术网

Python PYODBC TabError:缩进中制表符和空格的使用不一致

Python PYODBC TabError:缩进中制表符和空格的使用不一致,python,pypyodbc,Python,Pypyodbc,这是一个常见的问题,它似乎在这里,但在我的情况下,我找不到一个答案。为什么这里说制表符和缩进的使用不一致 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

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

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


还是一样的错误。我有一个例外,只是忘了把它包括在snippit@BenSmith尝试从这里复制粘贴我的代码。您的代码中可能混合了制表符和空格。您应该始终使用制表符进行缩进,或者始终使用空格。您应该将编辑器配置为始终使用空格替换选项卡,反之亦然。