[Tutor] Python
Kent Johnson
kent37 at tds.net
Fri Feb 13 12:50:21 CET 2009
On Fri, Feb 13, 2009 at 5:37 AM, Philip Cooper <philip.enid at tesco.net> wrote:
> Dear Tutor,
>
> I am preparing a data base saving it with pickle. I want to add additional
> information to the data base but seem to to have to recover the whole file
> from disc then add to it and save it again. Is there and append function
> within Pickle that will add information to the end of an existing file,
> similar to the append fuction used with text files, without recovering the
> file from the disc. The data file will eventually be quite large and I can
> see a time coming when there will be a time delay problem.
Pickle loads and saves whole objects. You can have multiple objects in
one file but if one object changes you have to re-write the file. So
if your database object is for example a big dict in which you are
changing or adding elements, you will have to rewrite the whole dict.
The shelve module provides a persistent dict that might be better
suited to what you are doing. But it sounds like you might be well
served by using a real database such as SQLite, which comes with
recent versions of Python.
Kent
More information about the Tutor
mailing list