Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Is it possible to convert a string to mapping?

I am trying to develop a program which involves plotting. I am using matplotlib as a backend to plot histograms. In order to give the users more control over the plotting, I am trying to take a string from the users of the form

str = '\{\'alpha\':\'0.2\'\}'

and then passing is to a histogram using

kwargs = str
plt.hist(X,Y,**kwargs)

I get a error saying that kwargs must be a mapping not a string. Is there a way to convert a string to kwargs mapping? I am not trying to do this so that it works just for alhpa, but any option that hist accepts.