gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:11:14 25 4
gpt4 key购买 nike

我正在尝试弄清楚如何将多行插入到 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))

关于python - 如何使用 Python 从列表中插入多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58170112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com