Tag Archives: pickle

lxml and shelve

As described in a previous post I use shelve a pickle based python module to serialize my letter objects so they do not have to stay in memory and can be cashed to increase performance. The problem that I encountered is that pickle does not like lxml objects. The problem is also described by other people here: http://stackoverflow.com/questions/8274438/saving-an-lxml-etree-elementtree-object

So, the easiest for me was to switch back to strings and instead to pickle lxml objects, I pickle an xml string and an object method on my custumn letter object that transforms the string into an lxml _Element object.