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()

1 Answer 1

3

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

valuesToInsert.append((fileName,tree.find('PNumber').text,tree.find('PNumber2').text))
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, it makes so much sense!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.