I have the following string which is a Python dictionary stringified:
some_string = '{123: False, 456: True, 789: False}'
How do I get the Python dictionary out of the above string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, you can do
But if the string contains user input, it’s a bad idea because some random malicious function could be in the expression. See Safety of Python 'eval' For List Deserialization
So a safer alternative might be:
From http://docs.python.org/library/ast.html#ast.literal_eval :