Python shelve is a convenient means of storing a Python data object to disk for later use. The feature behaves similarly to a Python dictionary object and uses a lot of the same syntax. Each object that is shelved has a key which is associated with the object so it can be quickly and efficiently accessed from disk. A shelved object must be something that can be pickled with the pickle package, essentially making shelves an easy way to organize and store pickled objects. "Pickling" is the process of making a Python object into a byte stream, and the inverse, "unpickling" is where the byte stream is restored back into the original Python object. Pickling is synonymous with serialization, marshalling, and flattening of data. Example Python objects that can be pickled include: integers, lists, tupules, sets, dictionaries, and classes. In addition to saving items to disk, shelves allow for quick access to portions of large data objects and can store them in binary format by specifying a protocol greater than 0. Here are some simple Python scripts that hopefully serve as a useful tutorial to learn about shelves and their syntax. The example focuses on saving dictionaries into a shelve, but it can be easily extended into other objects as well.
New to python and have been struggling with Shelves and using them. When I found this script it sounded like what was needed, more to the point not overwriting the existing data from one run to another. This script is above my knowledge base which I am attempting to improve on but for now can you detail what this script does and how, Would like to implement using input() and append, etc. on my script?
ReplyDelete