Assuming your lines are composed of strings like this:
line = "name1|9|111|replace|12|sds22|dsd|GDS-sw-E|1|1|0|No|21|43|No|0.1"
Since the delimiter is fixed, you can get the values directly by splitting:
Values = line.split("|")
gives Values
as
['name1', '9', '111', 'replace', '12', 'sds22', 'dsd', 'GDS-sw-E', '1', '1', '0', 'No', '21', '43', 'No', '0.1']
Basically, just loop over the lines and split them around the delimiter and then pass in your SQL insert statement. Something like:
cursor = conn.cursor()
SQLCommand = (
"INSERT INTO dbname.schema.table VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
)
lines = f.readlines() # assuming you opened your file with 'f = open("file.txt", "r")'
for line in lines:
Values = line.split("|")
cursor.execute(SQLCommand, Values)
conn.commit()
print("Data Successfully Inserted")
conn.close()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…