[Tutor] pickle problems
Richard D. Moores
rdmoores at gmail.com
Sun Aug 12 05:19:34 CEST 2012
On Sat, Aug 11, 2012 at 6:58 PM, eryksun <eryksun at gmail.com> wrote:
> On Sat, Aug 11, 2012 at 9:18 PM, eryksun <eryksun at gmail.com> wrote:
>>
> To clarify, you can store multiple pickles in a file, but each needs
> its own load. So you'd have to maintain a session dictionary for the
> factors of new integers. Then append the pickled session to the file
> when the user quits. When the program starts you'd have to loop
> through the file to update D with each pickled session.
Isn't that essentially what my script does?
> If you want an approach that's simpler and faster, use the shelve
> module. A shelf is a dictionary-like object that uses pickle to
> serialize objects stored to a database. The keys have to be strings,
> so your code would change to `D[str(n)] = factors`.
>
> http://docs.python.org/py3k/library/shelve.html#module-shelve
Yes, shelve is next, now that I have mastered (ha!) pickle.
Thanks again for the terrific help.
Dick
More information about the Tutor
mailing list