My code is as below. I am trying to have the str_list to be replaced as '10','11'
in the '{}'
but what I get is '10,11'
. May someone help me to get my desired output?
JavaScript
x
3
1
str_list = '10,11'
2
self.query= "select ball_name from ball_data where ball_type in ('{}')".format(str_list)
3
The desired query
JavaScript
1
2
1
"select ball_name from ball_data where ball_type in ('10','11')"
2
What I currently get is below
JavaScript
1
2
1
"select ball_name from ball_data where ball_type in ('10,11')"
2
Thanks to all.
Advertisement
Answer
Split it on ,
, add the single quotes, then join it back:
JavaScript
1
2
1
self.query = "... in ({})".format(",".join("'" + x + "'" for x in str_list.split(",")))
2