如何使用 Python 从列表中插入多行

how to insert multiple rows from list with Python

我正在尝试弄清楚如何将多行插入 python,但出现错误:

TypeError: ('Params must be in a list, tuple, or Row', 'HY000')

for folderName in os.listdir(parentDirectory):
    for fileName in os.listdir(parentDirectory+'/'+folderName+'/'+'people'):
        if os.path.splitext(fileName)[-1].lower()== '.xml':
            filePath = parentDirectory+'/'+folderName+'/'+'people'+'/'+fileName
            print(filePath)
            tree = ET.parse(filePath)

            valuesToInsert.append("('" + fileName + "','" +tree.find('PNumber').text+ "','" +tree.find('PNumber2').text+ "')")

            numberOfProcessedFiles += 1
            if numberOfProcessedFiles%1000 == 0:
                print(*valuesToInsert, sep = "\n")
                cursor.executemany('''
                    insert into t02.m.PNumbers
                    values
                    (?,?,?)
                    ''',valuesToInsert)

                conn.commit()
                valuesToInsert.clear()

不要追加字符串,只追加元组:

valuesToInsert.append((fileName,tree.find('PNumber').text,tree.find('PNumber2').text))