[Tutor] From SQL Blobs to Python Buffers to Actual Files
Steven D'Aprano
steve at pearwood.info
Sat Jun 5 01:42:00 CEST 2010
On Sat, 5 Jun 2010 03:51:02 am GoodPotatoes wrote:
> When I write the blob/binary data to a file and give it its original
> file name "customer1.rtf", I am expecting the application to read the
> binary data into text,excel,word documents, or whatever application
> created the file originally.
>
> Example:
> when I write blob1 to customer1.rtf, I get
> "xÚµVKsÛ6î93ù{ÈÁîÈ2%Û±cŸlgœdÒ<&vLJ²\J¨" as my first line.
Does that look like Rich Text Format to you? RTF looks like:
{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard
This is some {\b bold} text.\par}
It's a database blob. Writing it to a file called "customer1.rtf" won't
magically turn it into RTF any more than writing it to a file
called "puppy.jpg" will magically turn it into a picture of a puppy.
Blobs are database-specific binary data, not RTF. The database could be
doing *anything* to it -- it could be compressing it, or encoding it in
some way, who knows? You have to convert the data back into RTF before
writing it. This almost certainly isn't a Python problem, but a
database problem. Consult your database documentation, and good luck.
--
Steven D'Aprano
More information about the Tutor
mailing list