This might not scale, but based on your example and the current values this would work:
config = {
"SQL1": "select * from {x1}",
"SQL2": "select * from {x2}",
"SQL3": "select * from {x3}",
"SQL4": "select * from {x2}",
"SQL5": "select * from {x1}",
}
x1 = "test"
x2 = "test2"
x3 = "test3"
for sql in ["SQL1", "SQL2", "SQL3", "SQL4", "SQL5"]:
config_line = config[sql]
config_line = config_line.replace('{x1}', x1)
config_line = config_line.replace('{x2}', x2)
config_line = config_line.replace('{x3}', x3)
print(config_line)
The output is:
select * from test
select * from test2
select * from test3
select * from test2
select * from test
Another option is to use a template, modifying your input to match the template format.
from string import Template
config = {
"SQL1": "select * from $x1",
"SQL2": "select * from $x2",
"SQL3": "select * from $x3",
"SQL4": "select * from $x2",
"SQL5": "select * from $x1",
}
replacement_mapping = {
"x1": "test",
"x2": "test2",
"x3": "test3",
}
for sql in ["SQL1", "SQL2", "SQL3", "SQL4", "SQL5"]:
config_line = config[sql]
template = Template(config_line)
print(template.substitute(**replacement_mapping))
Then you can pass a dictionary of the standin variables and their replacement values.