0
votes

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?

str_list = '10,11'
self.query= "select ball_name from ball_data where ball_type in ('{}')".format(str_list)

The desired query

"select ball_name from ball_data where ball_type in ('10','11')"

What I currently get is below

"select ball_name from ball_data where ball_type in ('10,11')"

Thanks to all.

2

2 Answers

2
votes

Split it on ,, add the single quotes, then join it back:

self.query = "... in ({})".format(",".join("'" + x + "'" for x in str_list.split(",")))
0
votes
str_list = '10','11'
query= "select ball_name from ball_data where ball_type in {}".format(str_list)`