This seems to be a simple problem, but I have no idea how to correctly store and retrieve a list or a dictionary. If I pickle.dumps my list, it gets fed back to python as what python interprets as a tuple (e.g. all the \n get converted to literal \n s, and the beginning and closing () s tricks python into thinking this is a tuple.
This happens with correct insertion syntax (i.e. without %).
I have been working around this by creating a lot of columns, and using DictCursor, but that won't work with arbitrary dictionary keys (or with lists).
Could someone post a few short lines of code that will let me store and retrieve a list?
I feel silly for asking for something so simple, but I have literally wasted hours of my life in frustration on this problem.
Python 2.4 on Ubuntu Warty with MySQL 4.0.23 (default)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don't really understand what's wrong with pickle, but pickle's output is anyway a bit obtuse. If you are storing non-recursive collections of simple types then it should be sufficient to use repr() to encode and eval() to decode. Will this work? If not, can you give examples of your problem?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This seems to be a simple problem, but I have no idea how to correctly store and retrieve a list or a dictionary. If I pickle.dumps my list, it gets fed back to python as what python interprets as a tuple (e.g. all the \n get converted to literal \n s, and the beginning and closing () s tricks python into thinking this is a tuple.
This happens with correct insertion syntax (i.e. without %).
I have been working around this by creating a lot of columns, and using DictCursor, but that won't work with arbitrary dictionary keys (or with lists).
Could someone post a few short lines of code that will let me store and retrieve a list?
I feel silly for asking for something so simple, but I have literally wasted hours of my life in frustration on this problem.
Python 2.4 on Ubuntu Warty with MySQL 4.0.23 (default)
I don't really understand what's wrong with pickle, but pickle's output is anyway a bit obtuse. If you are storing non-recursive collections of simple types then it should be sufficient to use repr() to encode and eval() to decode. Will this work? If not, can you give examples of your problem?
Right then. This works. Very good.
(I just started progamming a few months ago - thats my excuse.)