![]() | Ned Batchelder : Blog | Code | Text | Site Pickle hiccups » Home : Blog : July 2003 |
Pickle hiccupsWednesday 23 July 2003 (This is not about deli after-effects: it's about Python). The pickle module is great: any Python data, simply serialized for storage, transmission, whatever. Nevertheless, Jarno writes about his difficulty with pickle. I don't have the same problem (I always go find my last use of it to copy from anyway), but I had two deeper problems with pickle recently: Problem one: You can't pickle instances of classes that are not declared at the top level of their module. This is clearly stated in the docs, but I had to discover it the hard way. I like to use private classes where the class is only needed within another class, and pickle can't handle it: # Bad: can't pickle Outer # Good: can pickle Outer Problem two: I had created an overly-tricky class that never returned an AttributeError: missing attributes simply returned None. This messed with pickle's head, because it tries to get the __getstate__ method on instances, and None is not callable. This wasn't really pickle's fault, more of an object lesson in how to override the deep magic methods like __getattr__.
tagged:
python» react | |
Comments
Add a comment: