Convert string to command..
Hrvoje Niksic
hniksic at xemacs.org
Thu Oct 18 12:02:56 EDT 2007
Abandoned <besturk at gmail.com> writes:
> import cPickle as pickle
> a="{2:3,4:6,2:7}"
> s=pickle.dumps(a, -1)
> g=pickle.loads(s);
> print g
> '{2:3,4:6,2:7}'
>
> Thank you very much for your answer but result is a string ??
Because you gave it a string. If you give it a dict, you'll get a
dict:
>>> import cPickle as pickle
>>> a = {1:2, 3:4}
>>> s = pickle.dumps(a, -1)
>>> g = pickle.loads(s)
>>> g
{1: 2, 3: 4}
If your existing database already has data in the "{...}" format, then
eval it only the first time. Then you'll get the dict which you can
cache thruogh the use of dumps/loads.
More information about the Python-list
mailing list