Lie Hetland book: Beginning Python..

Scott David Daniels scott.daniels at
Fri Nov 11 18:15:18 CET 2005

Magnus Lycka wrote:
> Vittorio wrote:
> Using the same symbol for both string substitutions and SQL placeholder
> such as pysqlite 1 and the MySQL interface does, is not really a bright
> idea in my opinion. Who thinks this is pretty?
> sql = "SELECT %s FROM %s WHERE %s = %%s"
> cur.execute(sql % (col,table,search_col), (param,))
> I think it's less confusing with:
> sql = "SELECT %s FROM %s WHERE %s = ?"
> cur.execute(sql % (col,table,search_col), (param,))
or you could use:

   sql = "SELECT %s FROM %s WHERE %s = %s"
   cur.execute(sql % (col,table,search_col, '%s'), (param,))

which I like better, because you don't have to read
extremely carefully for the double-percents.

--Scott David Daniels
scott.daniels at

More information about the Python-list mailing list