Converting a string to dictionary in python

python

Solution

First, 'dict' is the type name so not good for the variable name.

The following, does precisely as you asked...

a_dict = dict([str.strip('{}').split(":"),])

But if, as I expect, you want to add more mappings to the dictionary, a different approach is required.

Problem

I have the following string : ``` str = "{application.root.category.id:2}" ``` I would like to convert the above to a dictionary data type in python as in : ``` dict = {application.root.category.id:2} ``` I tried using eval() and this is the error I got: AttributeError: java package 'application' has no attribute "root" My current python is of <2.3 and I cannot update the python to >2.3 . Any solutions ?

Original source