[Tutor] Pickles and Shelves Concept

David Rock david at graniteweb.com
Fri Jun 7 19:14:12 EDT 2019


> On Jun 7, 2019, at 12:42, Gursimran Maken <gursimran.maken at gmail.com> wrote:
> 
> Hi All,
> 
> I am not getting the concept of pickle and shelves in python, I mean what's
> the use of both the concepts, when to use them in code instead of using
> file read and write operations.
> 
> Could anyone please explain me the concepts.

The simplest way to look at it is they are ways to save python data objects to disk.  That way, you can have a dataset in an already-usable format for later on use.
By contrast, file read/write is usually for raw data in/out in an unprocessed form that is not readily usable in your program.

So you would see something like this:

read data from file 
store data in a dictionary
pickle and shelve the dictionary for later


Then later on…
grab the shelved pickle
access the dict that was shelved


If the data you are working with will always be fresh/new, the file reads is probably more usable.  The shelving of data is most useful for easier retrieval later so you don’t have to re-process the raw data every time.


— 
David Rock
david at graniteweb.com






More information about the Tutor mailing list