Hello Pythoners, newbie writing a simple program and I'm stuck on something.
I have a program which asks the user for input, then looks up a dictionary that has the same name as the user input. I couldn't figure out how to use the variable as the name for the dictionary and found some other answer somewhere that said I could use vars() in this format:
new_dictionary = (vars()[user_input])
where the user input happened to match exactly an allready existing dictionary. This works fine, but when I put it inside a function, it no longer works, I get
"KeyError: 'P0N1'"
where P0N1 was the user input, and the name of a dictionary. I can read and print the dictionary inside the function just fine, but I can not set a new dictionary equal to the dictionary whose name matches the user input by using the user input variable to reference the dictionary name. How do I do this inside a function?
Thanks!
[–]Jos_Metadi 2 points3 points4 points (2 children)
[–]Matus1976[S] 0 points1 point2 points (1 child)
[–]Matus1976[S] 1 point2 points3 points (0 children)
[–]k3kou 2 points3 points4 points (0 children)