Re: python an sqlite objects

2008-12-04 Thread Bryan Olson
[EMAIL PROTECTED] wrote: >> # 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. [...] Why split at all? Just use sys.version_info: >>> import sys >>> a

Re: python an sqlite objects

2008-12-04 Thread skip
>> # 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. >> MRAB> [snip] MRAB> Why split on whitespace and then '.'? MRAB> assert int(sys.version.spl

Re: python an sqlite objects

2008-12-04 Thread MRAB
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

Re: python an sqlite objects

2008-12-04 Thread Bryan Olson
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

Re: python an sqlite objects

2008-12-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Bruno> If you serialize a dict, you'll obviously get a dict back. Note Bruno> that the point of json is *not* to replace pickle. json is a Bruno> *data* serialization format meant to represent "basic" types Bruno> (dicts, lists, strings and numbers) in

Re: python an sqlite objects

2008-12-04 Thread skip
Bruno> If you serialize a dict, you'll obviously get a dict back. Note Bruno> that the point of json is *not* to replace pickle. json is a Bruno> *data* serialization format meant to represent "basic" types Bruno> (dicts, lists, strings and numbers) in human readable and Bruno>

Re: python an sqlite objects

2008-12-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Bruno> Most of the time, you want to serialize the instance's __dict__. Does it recreate an instance at the other end or just a dict? If you serialize a dict, you'll obviously get a dict back. Note that the point of json is *not* to replace pickle. json is a *d

Re: python an sqlite objects

2008-12-03 Thread eric
On Dec 3, 10:21 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote: > azrael wrote: > > It logical that it would be more efficient and logical to use a object > > oriented database, but in this case I ask because of the portable > > nature of sqlite. > > > so, if I get it right, this should be possible [

Re: python an sqlite objects

2008-12-03 Thread Gerhard Häring
azrael wrote: It logical that it would be more efficient and logical to use a object oriented database, but in this case I ask because of the portable nature of sqlite. so, if I get it right, this should be possible [...] Did you try it? Did it work? If so,it was pure luck. Attached is a scri

Re: python an sqlite objects

2008-12-03 Thread skip
Bruno> Most of the time, you want to serialize the instance's __dict__. Does it recreate an instance at the other end or just a dict? Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: python an sqlite objects

2008-12-03 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Bruno> Or if you want something more portable, serialize the object to Bruno> json. At least you'll have a chance to deserialize it with some Bruno> other language. Assuming json can serialize more-or-less arbitrary Python objects. I assume the OP knows

Re: python an sqlite objects

2008-12-03 Thread azrael
It logical that it would be more efficient and logical to use a object oriented database, but in this case I ask because of the portable nature of sqlite. so, if I get it right, this should be possible >>> class a: >>> def __init__(self, a, b): >>> self.c = a+b >>> self.d = a*b >>> >>>

Re: python an sqlite objects

2008-12-03 Thread Gerhard Häring
[EMAIL PROTECTED] wrote: > azrael> is it possible to save a python object into a sqlite database as > azrael> an atribute of type BLOB > > Sure. Just pickle the object and save the resulting string. Be sure to save it as BLOB, not TEXT. Suppose you have serialized your object as Python

Re: python an sqlite objects

2008-12-03 Thread skip
Bruno> Or if you want something more portable, serialize the object to Bruno> json. At least you'll have a chance to deserialize it with some Bruno> other language. Assuming json can serialize more-or-less arbitrary Python objects. Can it serialize class instances? Skip -- http://ma

Re: python an sqlite objects

2008-12-03 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : azrael> is it possible to save a python object into a sqlite database as azrael> an atribute of type BLOB Sure. Just pickle the object and save the resulting string. Or if you want something more portable, serialize the object to json. At least you'll have

Re: python an sqlite objects

2008-12-03 Thread skip
azrael> is it possible to save a python object into a sqlite database as azrael> an atribute of type BLOB Sure. Just pickle the object and save the resulting string. -- Skip Montanaro - [EMAIL PROTECTED] - http://smontanaro.dyndns.org/ -- http://mail.python.org/mailman/listinfo/python-

python an sqlite objects

2008-12-03 Thread azrael
is it possible to save a python object into a sqlite database as an atribute of type BLOB -- http://mail.python.org/mailman/listinfo/python-list