What does it mean for an object to be picklable (or pickle-able)?

前端 未结 3 848
小鲜肉
小鲜肉 2020-12-14 14:30

Python docs mention this word a lot and I want to know what it means! Googling doesn\'t help much..

3条回答
  •  一个人的身影
    2020-12-14 14:59

    Things that are usually not pickable are, for example, sockets, file(handler)s, database connections, and so on. Everything that's build up (recursively) from basic python types (dicts, lists, primitives, objects, object references, even circular) can be pickled by default.

    You can implement custom pickling code that will, for example, store the configuration of a database connection and restore it afterwards, but you will need special, custom logic for this.

    All of this makes pickling a lot more powerful than xml, json and yaml (but definitely not as readable)

提交回复
热议问题