osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How Do You Replace Variables With Their Values?


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