TypeError: unsupported operand type(s) for %: 'tuple' and 'dict'
for
variable = '12345'
How to: “””insert into %(variable) ( id ) VALUES (%s)”””
idunidad = 2501
sql = ("""insert into %(variable)s ( id ) VALUES (%s)""")
if cursor.execute(sql, (idunidad,) % {table_name: table_name}):
db.commit()
cursor.close()
db.close()
the problem is that the code takes the variable name me strictly as text and not to assign the name of the variable it is.
the idea is to find the name of the variable ‘12345’ between the tables and if not create the table with the name of the variable:
else:
cursor.execute('''create table variable stocks (id)''')
cursor.execute(sql,(id,))
db.commit()
cursor.close()
db.close()
1 Answer