python get a list of expressions -


i have in config (ini) file:

result = "name\tage\tdob" 

this want final output (as list) - write output file real values written single line:

[str(row["name"]).strip(), str(row["age"]).strip(), str(row["dob"]).strip()] 

my python reads 'result' config file string , manupulation close need. stuck after that. did:

list1 = result.decode('string_escape').split() list2 = map(lambda x: x.replace('\"', ''), list1) list3 = map(lambda x: 'str(row[' + '"'  + x + '"' + ']).strip()', list2); print list3 

and prints list3 as:

['str(row["name"]).strip()', 'str(row["age"]).strip()', 'str(row["dob"]).strip()'] 

now, if notice, elements of list3 strings...which don't want. how ensure elements of list python expressions...? tried replace("'", ""), did not help.

any suggestion appreciated.

do instead:

list3 = map(lambda x: str(row[x]).strip(), list2); 

note that, of course, won’t see str(row["name"]).strip() in output rather whatever value evaluates to.


Popular posts from this blog