0

I'd like to build a query string with a variable length in where clause.

In PHP I might do this like

<?php
$vars=array('john','mike','matt');
$placeHolders=array_fill(0,sizeof($vars),'%s');
$whereClause=" name in (".join(',',$placeHolders).")";

Is there a concise Python translation of this in python

atxdba
  • 5,158
  • 5
  • 24
  • 30

1 Answers1

1

I think I'd use this to create the variable strings:

', '.join('%s' for _ in vars)

That eliminates the need to substring the result and gets you as many placeholders as you have values.

g.d.d.c
  • 46,865
  • 9
  • 101
  • 111