Menu

Store and Retrieve Dictionary

Help
cmutel
2005-10-04
2012-09-19
  • cmutel

    cmutel - 2005-10-04

    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)

     
    • Oliver Bock

      Oliver Bock - 2005-10-04

      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?

       
    • cmutel

      cmutel - 2005-10-04

      Right then. This works. Very good.

      (I just started progamming a few months ago - thats my excuse.)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.