Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Who is out there using pickle because they think it is a good idea? We use it because it is easy and builtin to the language and handles datetime by default!


Good thing JSON is in the standard library now too.


People really don’t get what pickle does apparently. The on disk format (could be JSON) is irrelevant.

I guess you could say JSON is pickle but restricted to only primitive types. The hard part is deciding what an to_json and from_json should be for an arbitrary Python object. That pair of methods is the pickle part.

“just write custom serializers for all objects you want to store to and load from disk and then invent a tagging system so you can keep track of what classes they were” is a surprisingly valid solution but it’s still different.


Obviously one of those cases where everyone's mileage varies, but the default JSON serialization has covered 99% of everything I've ever serialized/deserialized in Python without needing to write a to_json/from_json by hand. Needing those for 1% of cases seems fine. But also maybe I lean into duck typing a whole lot more than you do at the serialization boundary and don't need a lot of specific class types coming from JSON as long as the data is all in the same shape. You may think that's "primitives obsession", and I may think that a giant class hierarchy of custom objects is a bit non-Pythonic. We're both right, which is why, again, your mileage may vary here.


It just means that you usually deal with data that has a natural tree structure. The moment it becomes a graph, hands-off JSON serialization is broken - but Pickle isn't.


At a possibly serialized boundary sure. That doesn't mean I don't work with graphs, though, just that I guess I don't expect graphs to be entirely reified in memory at all times if I'm going to duck type walk through them. We all have different habits, of course.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: