我有这个人:
query = 'DELETE FROM boyd.%s WHERE teamid = %s AND id = %s AND year = %s' % (statstype, '%s', '%s', '%s')
self.executequery(query, values[0:3])
令我觉得丑陋。第一个%s实际上是由变量提供的,其他三个是绑定变量:我真的需要去% (statstype, '%s', '%s', '%s')
吗?这里有更多... pythonic方法吗?
答案 0 :(得分:0)
如果您使用双%%
个符号,则在字符串插值后仍会保留一个%
:
query = 'DELETE FROM boyd.%s WHERE teamid = %%s AND id = %%s AND year = %%s' % (statstype)
self.executequery(query, values[0:3])