newbie question: how to read back the dictionary from a file?

Amit Khemka khemkaamit at gmail.com
Mon Apr 16 06:11:42 EDT 2007


On 16 Apr 2007 03:03:40 -0700, lancered <wangday at gmail.com> wrote:
> Hi Dear all,
>
> I have some data here in the form of a dictionary, called "vdic". Then
> I write them to a data file "f" using   the write function as
> f.write(str(vdic)).  The keys of this dictionary are integers and
> values are float numbers. Something like this:
>
> { 1: 0.00951486513347, 2: 0.0388123556019, ... ...}
>
> Now, I want to read these data back in another function.  Of course, I
> could parse the string little by little, e.g, first read a "{", then
> loop read a int, then read a ":", then a float etc etc... Since it is
> written out with standard python builtin functions,  I guess there may
> be some more direct method than this, say a function in some modules?
> Could someone give me a hint?
>

Check out cPickle or shelve modules.

Cheers,
-- 
----
Amit Khemka -- onyomo.com
Home Page: www.cse.iitd.ernet.in/~csd00377
Endless the world's turn, endless the sun's Spinning, Endless the quest;
I turn again, back to my own beginning, And here, find rest.



More information about the Python-list mailing list