1

I am trying to figure out how to insert multiple rows into python but I get an error:

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()
donL
  • 1,290
  • 3
  • 13
  • 37

1 Answers1

3

Don't append a string, just append a tuple:

valuesToInsert.append((fileName,tree.find('PNumber').text,tree.find('PNumber2').text))
Simon Crane
  • 2,122
  • 2
  • 10
  • 21