String Literal to Blob

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Apr 9 07:14:22 CEST 2008


En Tue, 08 Apr 2008 13:55:07 -0300, Victor Subervi  
<victorsubervi at gmail.com> escribió:

> Thanks. I apparently am printing some holder for the image. I stripped  
> out
> most of it with this
> content[0][0]

Yes, because of this:
   content = cursor.fetchall()
fetchall returns a list of rows, each row a tuple of columns.

> but then I am left with this:
>
> array('c', '\xff\xd8\xff\xe0\\0\x10JFI...)
> How do I extract an image from that?

print content.tostring()
Or perhaps, replace that line with content.tofile(sys.stdout)

http://docs.python.org/lib/module-array.html

>> > #  print 'Content-Type: image/jpeg\r\nContent-Length: %d\n' %
>> len(content)

Once you fix the former, you can re-enable that line.

>> >   print 'Content-Type: image/jpeg\r\n'
>> >   print '<html><body>\n'
>> >   print content
>> >   print '</body><html>\n'
>> >   cursor.close()
>> >
>> > test()

>> > The commented out line gives me a leading less than sign...and that´s
>> > it. What do?

Try to understand now *why* you got a single character with your previous  
code.

-- 
Gabriel Genellina




More information about the Python-list mailing list