Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #98348 > unrolled thread

Questions on Pickle and Shelve

Started byVirgil Stokes <vs@it.uu.se>
First post2015-11-06 12:53 +0100
Last post2015-11-06 12:53 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Questions on Pickle and Shelve Virgil Stokes <vs@it.uu.se> - 2015-11-06 12:53 +0100

#98348 — Questions on Pickle and Shelve

FromVirgil Stokes <vs@it.uu.se>
Date2015-11-06 12:53 +0100
SubjectQuestions on Pickle and Shelve
Message-ID<mailman.83.1446810896.16136.python-list@python.org>
Here is snippet of Python (vers. 2.7.10) code that bothers me.

import cPickle as pickle

print "Pickle lists:"
dogs = ['Rover','King','Spot','Rufus']
cats = ['Mimi','Misty','Sasha']

with open('pickle.dat', 'wb') as pfile:
     pickle.dump(dogs, pfile)
     pickle.dump(cats,pfile)

del(dogs); del(cats)
with open('pickle.dat', 'rb') as pfile:
     dogs = pickle.load(pfile)
     cats = pickle.load(pfile)
     print dogs, '\n', cats, '\n'

import shelve

# Note! __exit__ attribute undefined for shelve
sfile = shelve.open('shelve.dat')
sfile['dogs'] = dogs
sfile['cats'] = cats
sfile.close()

print "Shelve entries:"
del(cats); del(dogs)
sfile = shelve.open('shelve.dat')
#print sfile
for key in sfile.keys():
     print key,' - ',sfile[key]
sfile.close()

1)  Which (the pickle or shelve code) takes less total RAM, if dogs and cats 
were very large?
2)  When the last shelve.open is given, is the entire contents of shelve.data 
transferred to RAM?  Note, if the print sfile is uncommented then the entire 
contents of shelve.data is printed out.

I was under the impression that the entire contents of a shelved file was not 
transferred to RAM when it was opened.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web