Store python list in MySQL
John Hunter
jdhunter at ace.bsd.uchicago.edu
Wed Jun 4 12:07:24 EDT 2003
>>>>> "John" == John Bradbury <john_bradbury at ___cableinet.co.uk> writes:
John> I can convert the list to a string and it works, but I don't
John> want to do that. Is there a way of storing Python Lists/
John> Dictionaries etc as binary using MySQLdb & then to be able
John> to reload them as Lists etc?
I'm assuming that when you say you can convert the list to a string,
you mean something like str(seq). If so, there's a better way using
pickle.
import pickle
s = pickle.dumps([1,2,'Hi', (1,2)])
s is now a string. Store it in the mysql BLOB, and you can get the
list back by
seq = pickle.loads(s)
print seq
John Hunter
More information about the Python-list
mailing list