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


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

Unshelving the data?

Started byUncle Ben <bgreen@nycap.rr.com>
First post2011-06-01 19:49 -0700
Last post2011-06-02 06:17 -0700
Articles 5 — 4 participants

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


Contents

  Unshelving the data? Uncle Ben <bgreen@nycap.rr.com> - 2011-06-01 19:49 -0700
    Re: Unshelving the data? Chris Torek <nospam@torek.net> - 2011-06-02 03:24 +0000
    Re: Unshelving the data? Ben Finney <ben+python@benfinney.id.au> - 2011-06-02 13:25 +1000
    Re: Unshelving the data? Adam Tauno Williams <awilliam@whitemice.org> - 2011-06-02 06:46 -0400
      Re: Unshelving the data? Uncle Ben <bgreen@nycap.rr.com> - 2011-06-02 06:17 -0700

#6834 — Unshelving the data?

FromUncle Ben <bgreen@nycap.rr.com>
Date2011-06-01 19:49 -0700
SubjectUnshelving the data?
Message-ID<4433955b-7f54-400a-af08-1f58a75e734c@j31g2000yqe.googlegroups.com>
Shelving is a wonderfully simple way to get keyed access to a store of
items. I'd like to maintain this cache though.

Is there any way to remove a shelved key once it is hashed into the
system?  I could do it manually by removing the value and erasing the
key in the directory list. But is there a more elegant way?

Or should I to go the full database route?  It is not a lage
application.

Ben

[toc] | [next] | [standalone]


#6835

FromChris Torek <nospam@torek.net>
Date2011-06-02 03:24 +0000
Message-ID<is6vpb0hds@news3.newsguy.com>
In reply to#6834
In article <4433955b-7f54-400a-af08-1f58a75e734c@j31g2000yqe.googlegroups.com>
Uncle Ben  <bgreen@nycap.rr.com> wrote:
>Shelving is a wonderfully simple way to get keyed access to a store of
>items. I'd like to maintain this cache though.
>
>Is there any way to remove a shelved key once it is hashed into the
>system?

$ pydoc shelve
...
    To summarize the interface (key is a string, data is an arbitrary
    object):
    ...
            d[key] = data   # store data at key (overwrites old data if
                            # using an existing key)
            data = d[key]   # retrieve a COPY of the data at key (raise
                            # KeyError if no such key) -- NOTE that this
                            # access returns a *copy* of the entry!
            del d[key]      # delete data stored at key (raises KeyError
                            # if no such key)
    ...

Seems pretty straightforward. :-)  Are you having some sort
of problem with "del"?
-- 
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W)  +1 801 277 2603
email: gmail (figure it out)      http://web.torek.net/torek/index.html

[toc] | [prev] | [next] | [standalone]


#6836

FromBen Finney <ben+python@benfinney.id.au>
Date2011-06-02 13:25 +1000
Message-ID<87wrh46hj1.fsf@benfinney.id.au>
In reply to#6834
Uncle Ben <bgreen@nycap.rr.com> writes:

> Or should I to go the full database route?  It is not a lage
> application.

I would recommend you at least investigate the use of SQLite for your
application. It is part of the standard library since Python 2.5
<URL:http://docs.python.org/library/sqlite3.html>.

-- 
 \       “Well, my brother says Hello. So, hooray for speech therapy.” |
  `\                                                      —Emo Philips |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#6856

FromAdam Tauno Williams <awilliam@whitemice.org>
Date2011-06-02 06:46 -0400
Message-ID<mailman.2389.1307013346.9059.python-list@python.org>
In reply to#6834
On Wed, 2011-06-01 at 19:49 -0700, Uncle Ben wrote:
> Shelving is a wonderfully simple way to get keyed access to a store of
> items. I'd like to maintain this cache though.

+1

> Is there any way to remove a shelved key once it is hashed into the
> system?  I could do it manually by removing the value and erasing the
> key in the directory list. But is there a more elegant way?

del shelve[key]

> Or should I to go the full database route?  It is not a lage
> application.

Stick with shelves.  Much simpler.

[toc] | [prev] | [next] | [standalone]


#6862

FromUncle Ben <bgreen@nycap.rr.com>
Date2011-06-02 06:17 -0700
Message-ID<e3de0622-e8aa-4b0b-a4a4-79b35e08090a@y12g2000yqh.googlegroups.com>
In reply to#6856
On Jun 2, 6:46 am, Adam Tauno Williams <awill...@whitemice.org> wrote:
> On Wed, 2011-06-01 at 19:49 -0700, Uncle Ben wrote:
> > Shelving is a wonderfully simple way to get keyed access to a store of
> > items. I'd like to maintain this cache though.
>
> +1
>
> > Is there any way to remove a shelved key once it is hashed into the
> > system?  I could do it manually by removing the value and erasing the
> > key in the directory list. But is there a more elegant way?
>
> del shelve[key]
>
> > Or should I to go the full database route?  It is not a lage
> > application.
>
> Stick with shelves.  Much simpler.

Thanks.  And Chris, thanks for showing me 'pyco'. I had looked in six
thick books and had not found anything on removing keys.

Ben

[toc] | [prev] | [standalone]


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


csiph-web