Common use-cases for pickle in Python

后端 未结 9 1579
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 04:56

I\'ve looked at the pickle documentation, but I don\'t understand where pickle is useful.

What are some common use-cases for pickle?

9条回答
  •  情深已故
    2020-12-02 05:18

    Minimal roundtrip example..

    >>> import pickle
    >>> a = Anon()
    >>> a.foo = 'bar'
    >>> pickled = pickle.dumps(a)
    >>> unpickled = pickle.loads(pickled)
    >>> unpickled.foo
    'bar'
    

    Edit: but as for the question of real-world examples of pickling, perhaps the most advanced use of pickling (you'd have to dig quite deep into the source) is ZODB: http://svn.zope.org/

    Otherwise, PyPI mentions several: http://pypi.python.org/pypi?:action=search&term=pickle&submit=search

    I have personally seen several examples of pickled objects being sent over the network as an easy to use network transfer protocol.

提交回复
热议问题