I'm trying to generate a sql script in python but when I try to run the code the following error appears can only concatenate str (not "float") to str.
how to solve this problem
with open ("output.txt", "w"):
for index, row in df.iterrows():
print('INSERT INTO ' + TABLE_NAME + '(\'COD_TXT\' , \'DES_TXT\' ,\'DES_OBS_TXT\') VALUES (', row['COD_TXT'],',\''+row['DES_TXT']+'\'',',\''+row['DES_OBS_TXT']+'\');', file=open("output.txt", "a"))
I'm entering data like
"COD_TXT";"DES_TXT";"DES_OBS_TXT"
"1000";"teste de texto";"Migração.xml"
"1001";"esse é um novo texto";"Migração.xml"
"1002";"Selecione uma das opções";"Migração.xml"
and I would like the data to come out this way
INSERT INTO TEXTO_FRONTEND('COD_TXT' , 'DES_TXT' ,'DES_OBS_TXT') VALUES ( 1000,'teste de texto','Migração.xml');
INSERT INTO TEXTO_FRONTEND('COD_TXT' , 'DES_TXT' ,'DES_OBS_TXT') VALUES ( 1001,'esse é um novo texto','Migração.xml');
INSERT INTO TEXTO_FRONTEND('COD_TXT' , 'DES_TXT' ,'DES_OBS_TXT') VALUES (1002,'Selecione uma das opções','Migração.xml');
What I have tried:
with open ("output.txt", "w"):
for index, row in df.iterrows():
print('INSERT INTO ' + TABLE_NAME + '(\'COD_TXT\' , \'DES_TXT\' ,\'DES_OBS_TXT\') VALUES (', row['COD_TXT'],',\''+row['DES_TXT']+'\'',',\''+row['DES_OBS_TXT']+'\');', file=open("output.txt", "a"))