Convert String to Dictionary question

john coppola john_coppola_r_s at yahoo.com
Thu Feb 14 16:29:56 EST 2002


even better to use to use cPickle.

--- Jason Orendorff <jason at jorendorff.com> wrote:
> > I saved my dictionary {'hello1': [1, 0, 0]} to a
> file.
> > When I do a readline the I get back a string.
> > How do I convert this string to a dictionary?
> 
> It's better to save data using pickle.
>  
>
http://www.python.org/doc/current/lib/module-pickle.html
> 
> import pickle
> mydata = {'hello1': [1, 0, 0]}
> 
> # How to store data
> f = open('mydata.dat', 'wb')
> pickle.dump(mydata, f, 1)
> f.close()
> 
> # How to load data back
> f = open('mydata.dat', 'rb')
> mydata = pickle.load(f)
> f.close()
> 
> ## Jason Orendorff    http://www.jorendorff.com/
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list


__________________________________________________
Do You Yahoo!?
Send FREE Valentine eCards with Yahoo! Greetings!
http://greetings.yahoo.com




More information about the Python-list mailing list