I am trying to understand the following simplified python code snippet from an existing working project. The code will throw error beneath the code below. It would be greatly appreciated if anyone can enlighten me on how to fix it. Thank you very much in advance.
from munch import Munch
imp_command = "impala-shell -k -i edgenode01 --ssl -B -q 'select * from "
file_name = 'file_name'
def run(name, cmd, parms):
parms = imp_command + file_name + ";'"
lower_parms = Munch()
for parm in parms:
lower_parms[parm.lower()] = parms[parm]
parms = lower_parms
print(parms)
run('Name', 'CMD',{imp_command + '${DB}.${VERSION}_' + file_name + ";'"} )
Error:
Traceback (most recent call last):
File "./test.py", line 13, in <module>
run('Name', 'CMD',{imp_command + '${DB}.${VERSION}_' + file_name + ";'"} )
File "./test.py", line 9, in run
lower_parms[parm.lower()] = parms[parm]
TypeError: string indices must be integers
Update 20190127:
The original project is set up to use Munch to somehow generate the 'CMD' in the run command, the {DB} and {VERSION} are defined in a seperate config file that the final script will import another utility to read the config so please assume {DB} and {VERSION} are string.
The existing format(or usage) is defined in the function def run(name, cmd, parms)
.
example below:
imp_command = "impala-shell -k -i edgenode01 --ssl -B -q 'select * from "
file_name = 'file_name'
task.run('Select SQL table in Impala', 'ImpalaCommand', {'CMD': imp_command + '${DB}.${VERSION}_' + file_name})
name and cmd are strings parms will be imp_command + '${DB}.${VERSION}_' + file_name + ";'" and after run(name, cmd, parms), I am expecting to get a string below:
"impala-shell -k -i edgenode01 --ssl -B -q 'select * from file_name ;'"
file_name is used as the table name in impala database.