I’m trying to figure out what the following line does exactly – specifically the %%s part?
cursor.execute('INSERT INTO mastertickets (%s, %s) VALUES (%%s, %%s)'%sourcedest, (self.tkt.id, n))
Any good mini-tutorial about string formatting and inserting variables into strings with Python?
The
%%becomes a single%. This code is essentially doing two levels of string formatting. First the%sourcedestis executed to turn your code essentially into:then the db layer applies the parameters to the slots that are left.
The double-% is needed to get the db’s slots passed through the first string formatting operation safely.