I have a list of dictionary items stored in variable List_dicts, and I have to write a selected list of items from the above list into a file. given below my python function:
def write_items(List_dicts,key_list):
#List_dicts contains the list if dicts
#key_list contains the key separated by comma
k_list=key_list.split(',')
write_string=''
for i in k_list:
write_string=write_string+"item['"+i+"'],"
f=open('log.txt','w')
for item in List_dicts:
f.write(write_string[0:len(write_string)-1]) #this should write item['key1'],item['key2'],item['key3']..,item['keyn'] not the value of string 'write_string'
f.close()
Is this possible in anyways? I was inspired from SQL dynamic execute quires.