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


Groups > comp.lang.python > #98348

Questions on Pickle and Shelve

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Virgil Stokes <vs@it.uu.se>
Newsgroups comp.lang.python
Subject Questions on Pickle and Shelve
Date Fri, 6 Nov 2015 12:53:43 +0100
Lines 44
Message-ID <mailman.83.1446810896.16136.python-list@python.org> (permalink)
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de EeZJqDiBsbebx+YUsr1F5w7WYoIQbY/27ESEAwg3wS8w==
Return-Path <vs@it.uu.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'skip:[ 20': 0.03; 'undefined': 0.07; '#print': 0.09; "'rb')": 0.09; 'given,': 0.09; 'skip:[ 30': 0.09; 'snippet': 0.09; 'python': 0.10; 'opened.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'attribute': 0.18; '(the': 0.22; 'subject:Questions': 0.22; 'import': 0.24; 'header:User-Agent:1': 0.26; 'pickle': 0.29; 'received:se': 0.29; 'print': 0.30; 'code': 0.30; 'impression': 0.33; 'ram': 0.33; 'file': 0.34; 'to:addr:python-list': 0.36; 'skip:p 20': 0.38; 'takes': 0.39; 'to:addr:python.org': 0.40; 'entire': 0.61; 'total': 0.62; 'here': 0.66; 'transferred': 0.72; 'ram,': 0.84
X-SENDER-IP [213.112.59.157]
X-LISTENER [smtp.bredband.net]
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result A2D/AQCnlDxWOZ07cNUNURkKAQECBgMCiye5NxKHcxEBAQEBAQEBBgEBAQEhIIUeFUA2AgUWCwILAwIBAgExJAMIAQGIL69LcZEkgQGFU4olgk6BRAWWSHyobDeEMYYFAQEB
X-IPAS-Result A2D/AQCnlDxWOZ07cNUNURkKAQECBgMCiye5NxKHcxEBAQEBAQEBBgEBAQEhIIUeFUA2AgUWCwILAwIBAgExJAMIAQGIL69LcZEkgQGFU4olgk6BRAWWSHyobDeEMYYFAQEB
X-IronPort-AV E=Sophos;i="5.20,251,1444687200"; d="scan'208";a="348494730"
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:98348

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web