David Bear <[EMAIL PROTECTED]> wrote:
> I need to store pickled objects in postgresql. I reading through the pickle
> docs it says to always open a file in binary mode because you can't be sure
> if the pickled data is binary or text. So I have 2 question. Can I set the
> pickle to be text -- and then store it in a 'text' type field in my sql
> table, or should what sql type should I save the pickle as?
You could always encode it into text form, eg
>>> from cPickle import dumps, loads
>>> a = range(10)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> b = dumps(a).encode("zip").encode("base64").strip()
>>> b
'eJzTyCkw5PI04Er0NARiIyA2BmITIDYFYjMgNgdiCyC25ErUAwD5DQqD'
>>> loads(b.decode("base64").decode("zip"))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list