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


Groups > comp.lang.python > #11852

Re: Replacement for the shelve module?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <t@jollybox.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'subject:module': 0.04; 'json': 0.07; 'sqlite': 0.07; 'suggestions.': 0.07; 'python': 0.08; 'deprecated': 0.09; 'folks,': 0.09; 'deprecation': 0.16; 'likewise': 0.16; 'received:192.168.1.40': 0.16; 'symbol,': 0.16; 'written': 0.16; 'wrote:': 0.16; 'advance': 0.18; 'header:In- Reply-To:1': 0.22; 'dictionary': 0.23; 'module,': 0.23; "shouldn't": 0.23; "i'm": 0.27; 'lists': 0.28; 'module': 0.30; 'object.': 0.30; 'url:dev': 0.30; 'thanks': 0.30; 'url:library': 0.31; 'subject:?': 0.31; 'list': 0.32; 'value.': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.33; 'however,': 0.34; '...': 0.34; 'header:User-Agent:1': 0.34; '(as': 0.34; 'like:': 0.34; 'replacement': 0.34; 'sense,': 0.34; 'weird': 0.34; 'data,': 0.35; 'object': 0.35; 'file': 0.36; 'url:python': 0.36; 'data.': 0.36; 'doing': 0.36; 'using': 0.37; 'but': 0.37; 'could': 0.38; 'think': 0.38; 'some': 0.38; 'url:org': 0.38; 'should': 0.38; 'easier': 0.38; 'subject:: ': 0.39; 'received:192': 0.39; 'url:docs': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'might': 0.40; "it's": 0.40; 'huge': 0.61; 'easily': 0.61; 'your': 0.61; 'received:62': 0.70; 'database.': 0.74; 'prices': 0.76; '2],': 0.84; 'calculations': 0.84; 'from:addr:t': 0.84; 'subject:Replacement': 0.84
Date Fri, 19 Aug 2011 17:54:29 +0200
From Thomas Jollans <t@jollybox.de>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:6.0) Gecko/20110816 Thunderbird/6.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Replacement for the shelve module?
References <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com>
In-Reply-To <1e35ff5e-785e-41db-a50f-976e6ef60692@h9g2000vbr.googlegroups.com>
X-Enigmail-Version 1.3
OpenPGP id=5C8691ED
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.225.1313769596.27778.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1313769596 news.xs4all.nl 23930 [2001:888:2000:d::a6]:40687
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:11852

Show key headers only | View raw


On 19/08/11 17:31, Forafo San wrote:
> Folks,
> What might be a good replacement for the shelve module, but one that
> can handle a few gigs of data. I'm doing some calculations on daily
> stock prices and the result is a nested list like:
> 
> [[date_1, floating result 1],
>  [date_2, floating result 2],
> ...
>  [date_n, floating result n]]
> 
> However, there are about 5,000 lists like that, one for each stock
> symbol. Using the shelve module I could easily save them to a file
> ( myshelvefile['symbol_1') = symbol_1_list) and likewise retrieve the
> data. But shelve is deprecated AND when a lot of data is written
> shelve was acting weird (refusing to write, filesizes reported with an
> "ls" did not make sense, etc.).
> 
> Thanks in advance for your suggestions.

Firstly, since when is shelve deprecated? Shouldn't there be a
deprecation warning on http://docs.python.org/dev/library/shelve.html ?

If you want to keep your current approach of having an object containing
all the data for each symbol, you will have to think about how to
serialise the data, as well as how to store the documents/objects
individually. For the serialisation, you can use pickle (as shelve does)
or JSON (probably better because it's easier to edit directly, and
therefore easier to debug).
To store these documents, you could use a huge pickle'd Python
dictionary (bad idea), a UNIX database (dbm module, anydbm in Python2;
this is what shelve uses), or simple the file system: one file per
serialised object.

Looking at your use case, however, I think what you really should use is
a SQL database. SQLite is part of Python and will do the job nicely.
Just use a single table with three columns: symbol, date, value.

Thomas

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


Thread

Replacement for the shelve module? Forafo San <ppv.grps@gmail.com> - 2011-08-19 08:31 -0700
  Re: Replacement for the shelve module? Ken Watford <kwatford@gmail.com> - 2011-08-19 11:49 -0400
  Re: Replacement for the shelve module? Thomas Jollans <t@jollybox.de> - 2011-08-19 17:54 +0200
    Re: Replacement for the shelve module? Forafo San <ppv.grps@gmail.com> - 2011-08-19 09:21 -0700
  Re: Replacement for the shelve module? Miki Tebeka <miki.tebeka@gmail.com> - 2011-08-19 10:15 -0700
  Re: Replacement for the shelve module? Robert Kern <robert.kern@gmail.com> - 2011-08-19 12:45 -0500
  Re: Replacement for the shelve module? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-20 06:36 +1000
    Re: Replacement for the shelve module? Robert Kern <robert.kern@gmail.com> - 2011-08-19 17:24 -0500
      Re: Replacement for the shelve module? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-20 11:38 +1000
        Re: Replacement for the shelve module? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-08-21 12:37 +1200
          Re: Replacement for the shelve module? Chris Angelico <rosuav@gmail.com> - 2011-08-21 01:54 +0100

csiph-web