What is the difference between pickle and shelve?

前端 未结 2 1822
灰色年华
灰色年华 2020-12-12 14:15

I am learning about object serialization for the first time. I tried reading and \'googling\' for differences in the modules pickle and shelve but I am not sure I understand

2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-12 14:55

    According to pickle documentation:

    Serialization is a more primitive notion than persistence; although pickle reads and writes file objects, it does not handle the issue of naming persistent objects, nor the (even more complicated) issue of concurrent access to persistent objects. The pickle module can transform a complex object into a byte stream and it can transform the byte stream into an object with the same internal structure. Perhaps the most obvious thing to do with these byte streams is to write them onto a file, but it is also conceivable to send them across a network or store them in a database. The shelve module provides a simple interface to pickle and unpickle objects on DBM-style database files.

提交回复
热议问题