TypeError 元组索引必须是整数或切片而不是日期时间

TypeError tuple indices must be integers or slices not datetime

我试图将某个记录的某个索引从对象传递到我的主函数,但是在这样做时我得到了这个元组错误。这两个记录都是时间类型,我不确定我做错了什么导致了这个。如果我能进一步澄清任何事情,请告诉我。

load_file.py

def get_connection():
    cursor = connection.cursor()
    cursor.execute(
        "SELECT ID, Type, Server, Port, User, Password, isActive, FileExtension, FileContains, FileLocation, "
        "ScheduleMinutes, IntervalTime from DataConnection WHERE isActive=True")

    return cursor.fetchall()


class FileData:
    def __init__(self):
        self.interval_time = None
        self.schedule_minutes = None

    def data_connection(self, data_connection_detail):
        self.schedule_minutes = data_connection_detail[10]
        self.interval_time = data_connection_detail[11]

main.py

from load_file import get_connection
from load_file import FileData



def run_engine():
    file_data = FileData()
    while True:
        data = get_connection()
        for data_connection_detail in data:
            file_data.data_connection(data_connection_detail)
            schedule_minutes = data_connection_detail[file_data.schedule_minutes]
            interval_time = data_connection_detail[file_data.interval_time]

            download_files(data)
            import_records(data)


if __name__ == "__main__":
    run_engine()

您不需要从 data_connection_detail 检索 schedule_minutesinterval_time,因为 FileData.data_connection() 方法已经为您完成了。

def run_engine():
    file_data = FileData()
    while True:
        data = get_connection()
        for data_connection_detail in data:
            file_data.data_connection(data_connection_detail)
===
-           schedule_minutes = data_connection_detail[file_data.schedule_minutes]
-           interval_time = data_connection_detail[file_data.interval_time]
===
+           schedule_minutes = file_data.schedule_minutes
+           interval_time = file_data.interval_time
===
            download_files(data)
            import_records(data)