[Tutor] From SQL Blobs to Python Buffers to Actual Files

GoodPotatoes goodpotatoes at yahoo.com
Fri Jun 4 02:57:07 CEST 2010


Environment:
Sybase/ODBC/Windows/Python2.5

I have been given a legacy database, and need to read the binaryfiles out to a disk.  The table has columns "filename" and "binaryFile", where the binaryFile is a BLOB

My python script so far is:

import pyodbc
cnxn=pyodbc.Connection("DSN=sybasedatabase")
cursor=cnxn.cursor()

p=cursor.execute("select top 1 * from FOO..Table").fetchone()

#p contains ('UsersOldFile.rtf', <read-only buffer for 0x010E1540, size 1496, offset 0 at 0x010C04E0>)

#I tried to write this out to the disk as:
myfile=open(p[0],'wb')
myfile.write(p[1])
myfile.close()

#but all I get is gibberish.  Is there another way to handle the buffer, or something else I'm missing?


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100603/668e9752/attachment.html>


More information about the Tutor mailing list