Bryan Olson wrote:
Gerhard Häring wrote:
Be sure to save it as BLOB, not TEXT.
Suppose you have serialized your object as Python bytestring.
serialized = ...
... .execute("insert into mytable(mycolumn) values (?)",
(sqlite3.Binary(serialized),))
This way you will get a BLOB in the form of a Python buffer object when
you later select it from the database [...]
Good advice for now, with Python 2.X. Python 3 resolves most of
confusion with its distinction between the string type and the bytes
types. The 3.x standard library sqlite3 module understands the 'bytes'
and 'bytearray' types, and treats them appropriately.
Here's a runnable Python 3 demo:
# Ensure that we're running Python 3 or later.
import sys
assert int(sys.version.split()[0].split('.')[0]) >= 3
# If there's a better way to chek, please tell.
[snip]
Why split on whitespace and then '.'?
assert int(sys.version.split('.')[0]) >= 3
--
http://mail.python.org/mailman/listinfo/python-list