How Do You Replace Variables With Their Values?

Terry Reedy tjreedy at udel.edu
Thu Jul 11 14:36:06 EDT 2019


On 7/11/2019 12:51 AM, Aldwin Pollefeyt wrote:
> dinner = {'Starters':['Fried Calamari', 'Potted crab'],'Main
> Course':['Fish', 'Meat'], 'Desert':['Cake', 'Banana Split']}
> 
> # Don't ask where I got the dinner from
> 
> for meal in dinner.keys():
>      exec(meal.replace(' ','_') + ' = list(dinner[meal])')

If dinner came from an untrusted source, and the OP does not say 
differently, this would be a stupid thing to do.

-- 
Terry Jan Reedy




More information about the Python-list mailing list