[Python] Simplest possible serialization/marshalling

Everyone knows about pickle.

But here is something much, much simpler. LISP-like serialization via text strings.

>>> salary={'john':1234, 'peter':5678}
>>> str(salary)
"{'john': 1234, 'peter': 5678}"
>>> serialized=str(salary)
>>> serialized
"{'john': 1234, 'peter': 5678}"
>>> eval(serialized)
{'john': 1234, 'peter': 5678}

But beware -- eval() may be very dangerous. If attacker can control the input string, he/she can do some nasty things.

(the post first published at 20230128.)

List of my other blog posts.

Subscribe to my news feed

Yes, I know about these lousy Disqus ads. Please use adblocker. I would consider to subscribe to 'pro' version of Disqus if the signal/noise ratio in comments would be good enough.