Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 971089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:54:25+00:00 2026-05-16T02:54:25+00:00

For this example, I have a dictionary, that when I call on it, Ember

  • 0

For this example, I have a dictionary, that when I call on it, “Ember Attack” is displayed.

#import shelve
class Pokemon():
"""Each pokemon's attributes"""

def __init__(self):
    self.id=[]
    self.var1=[]
    self.var2=[]
    self.var3=[]
    self.var4=[]
    self.var5=[]

def __str__(self):
     showList=['id','var1', 'var2', 'var3', 'var4', 'var5']

#dict1=shelve.open("shelve.dat")
dict1={}
dict1["Charmander"]=Pokemon()
dict1["Charmander"].var1="Ember Attack"
#dict1.sync()
print dict1["Charmander"].var1
#dict1.close()

However when I start using shelves instead of the dictionary, I get a blank when I call on var1.

import shelve

class Pokemon():
"""Each patient's attributes"""

def __init__(self):
    self.id=[]
    self.var1=[]
    self.var2=[]
    self.var3=[]
    self.var4=[]
    self.var5=[]

def __str__(self):
    showList=['id','var1', 'var2', 'var3', 'var4', 'var5']

dict1=shelve.open("shelve.dat")
#dict1={}

dict1["Charmander"]=Pokemon()
dict1["Charmander"].var1="Ember Attack"

dict1.sync()

print dict1["Charmander"].var1

dict1.close()

The only difference is that I made dict1 a shelve dictionary instead of a regular dictionary. It probably has to do with memory scope or something. Anyway, can someone help me revise my code so that it will work with shelves? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:54:26+00:00Added an answer on May 16, 2026 at 2:54 am
    dict1=shelve.open("shelve.dat", writeback=True)
    

    you can also specify the protocol which should improve performance

    dict1=shelve.open("shelve.dat", protocol=2, writeback=True)
    

    Because of Python semantics, a shelf
    cannot know when a mutable
    persistent-dictionary entry is
    modified. By default modified objects
    are written only when assigned to the
    shelf (see Example). If the optional
    writeback parameter is set to True,
    all entries accessed are also cached
    in memory, and written back on sync()
    and close(); this can make it handier
    to mutate mutable entries in the
    persistent dictionary, but, if many
    entries are accessed, it can consume
    vast amounts of memory for the cache,
    and it can make the close operation
    very slow since all accessed entries
    are written back (there is no way to
    determine which accessed entries are
    mutable, nor which ones were actually
    mutated).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this example: public class Inheritance { public static class Animal { public
I have seen this example on the web: $('#questionTextArea').each( function() { var $this =
My example dictionary is this data_dictionary = {1:'blue',2:'green',3:'red',4:'orange',5:'purple',6:'mauve'} The data_dictionary can have more elements
I have a base class that has the following property: public virtual Dictionary<String, int>
I have a ViewModel class that implements the IDataErrorInfo Interface . In each property's
I have a class whose instances have attributes that are containers which themselves contain
I have a basic sound manager class that's derived from an online example: http://www.xnawiki.com/index.php?title=Basic_Sound_Manager_For_XNA_GS_3.0
So I have a dictionary that looks like this when I print it: {'10':
In this example we have 3 related tables on a SQLite database: CREATE TABLE
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.