I have a parameter file
sqlparams.py
ref_var1 = '(1,2,3)'
ref_var2 = "('a','b','c')"
ref_var3 = "(1,2,3,4)"
rawsql.txt
select *
from emp.data
where id in ref_var1 and
name in ref_var2 and
idn in ref_var3
I'm trying to pass params from sqlparams.py file to rawsql.txt file to generate a new file called exec_sql_file.txt
This is what have got so far
import sqlparams
# filter non non built-in variable names
variables = [k for k in sqlparams.__dict__ if '__' not in k]
with open('rawsql.txt', 'r') as f:
content = f.read()
for v in variables:
content = content.replace(v, getattr(params, v))
with open('exec_sql_file.txt', 'w') as f:
f.write(content)
However I get the following error
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-15-d376e3c45949> in <module>()
1
2 for v in variables:
----> 3 content = content.replace(v, getattr(params, v))
4 with open('exec_sql_file.txt', 'w') as f:
5 f.write(content)
AttributeError: 'module' object has no attribute 'ref_var3'
Aucun commentaire:
Enregistrer un commentaire