is there a module to work with pickled objects storage in database?

Paul Boddie paul at boddie.org.uk
Fri May 4 06:37:35 EDT 2007


On 4 Mai, 12:18, "krishnakant Mane" <researchb... at gmail.com> wrote:
>
> I first dump the object into the file through pickle.dump and then
> open the file in read mode.
> then I read the contents of the file and then store what ever comes
> out into the blob field.
> I know this is not right and there should be ways of storing a pickled
> object other than file.

Try pickle.dumps to produce a string containing the pickled object.
Obviously, you then need to supply the string to the database using
the normal DB-API mechanisms. That said, although I haven't done much
work with BLOBs in the DB-API, it would surprise me if it were not
possible with some database modules to pass a file-like object as a
parameter to the cursor's execute method, although I don't recall
there being any classes whose objects act like files and produce
pickled objects on demand.

Paul




More information about the Python-list mailing list