python an sqlite objects
google at mrabarnett.plus.com
Thu Dec 4 19:28:35 CET 2008
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 (?)",
>> 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().split('.')) >= 3
> # If there's a better way to chek, please tell.
Why split on whitespace and then '.'?
assert int(sys.version.split('.')) >= 3
More information about the Python-list