Wow, I'm so sorry I answered on the question : "How do you replace a variable with its value". For what i understood with the example values, CrazyVideoGamez wants 3 variables named like the meal-names in dictionary. Yes, it's not secure unless you work with your own dataset (just like sending your own created commands with set=True in subprocess). Yes there might be better solutions for the real problem. But maybe the user really has a purpose for it, in a secure environment with own datatset, it's a valid answer for "How do you replace a variable with its value".
On Fri, Jul 12, 2019 at 12:10 PM Ben Finney <ben+pyt...@benfinney.id.au> wrote: > Aldwin Pollefeyt <aldwinaldwin...@gmail.com> writes: > > > 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])') > > > > print(Starters) > > print(Main_Course) > > print(Desert) > > Why do you think this is needed? Why (there may be some reason! but you > have not told us what that is) can your program not just:: > > print(dinner['Starters']) > print(dinner['Main Course']) > print(dinner['Desert']) > > > OUTPUT: > > ['Fried Calamari', 'Potted crab'] > > ['Fish', 'Meat'] > > ['Cake', 'Banana Split'] > > The above code produces this output, without any need for binding new > names. So what is it you are actually trying to achieve, and why do you > think the new bindings are necessary? > > -- > \ “The number of UNIX installations has grown to 10, with more | > `\ expected.” —Unix Programmer's Manual, 2nd Ed., 1972-06-12 | > _o__) | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list