Should I use marshal if I am getting comma errors in JSON (Python)? -
i using python dump huge data structure (multiple lists , dictionaries) , sending on socket client.
i keep getting valueerror: 'expecting ',' delimiter: line 1 column 16177 (char 16176) @ various different locations every time run program (it column 25000, or column 13000, keeps changing).
should use marshal instead of json (or pickle)? reliable format large file sizes?
i'd suggest use pickle (or cpickle if you're on python 2.x) can serialize anything, including user-defined classes. and, docs say
the
marshalserialization format not guaranteed portable across python versions. because primary job in life support.pycfiles, python implementers reserve right change serialization format in non-backwards compatible ways should need arise.pickleserialization format guaranteed backwards compatible across python releases.
(emphasis mine).
another advantage of pickle:
the
picklemodule keeps track of objects has serialized, later references same object won’t serialized again.marshaldoesn’t this.this has implications both recursive objects , object sharing. recursive objects objects contain references themselves. these not handled marshal, , in fact, attempting marshal recursive objects crash python interpreter. object sharing happens when there multiple references same object in different places in object hierarchy being serialized.
picklestores such objects once, , ensures other references point master copy. shared objects remain shared, can important mutable objects.
you can use dill if pickle fails serialize data.
Comments
Post a Comment