How can I turn this string
"((145541L, u'/.stats/'), (175706L, u'///')"
to a json object in python such as
{'145541' : '/.stats/',
'175706' : '///'
}
I’ve been trying tuple() and others but it does
Thanks
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.
You do most probably have a tuple of tuples, and want to create a dictionary. To do so, try the following:
If what you have is really a string, add the initial line:
As pointed by @Volatility,
evalmay be dangerous, since it evaluates any piece of code, not only literals. This way someone could execute commands on your program if you received commands on your strings.To avoid so, you may use
ast.literal_evalinstead: