Modifying Class Object

Duncan Booth duncan.booth at invalid.invalid
Mon Feb 8 10:00:37 CET 2010

T <misceverything at> wrote:

> Oops, this one was my fault - the object I was having the issues with
> was actually a shelve file, not a just re-assigning the
> variable isn't working, but re-writing the object to the shelve file
> does.  So in this case, is there any way to just change a single
> value, or am I stuck rewriting the entry?

Either open the shelve with writeback=True or rewrite the entry.
Rewriting the entry isn't hard: you can just re-use the same value:

def changevalue():
    for key in mytest.keys():
        temp = mytest[key]
        temp.param3 = "newvalue"
        mytest[key] = temp

If you really are changing every item in the shelve using writeback=True 
will be much simpler, but if you are only changing a few then just tell the 
shelve that you've updated them as above.

Duncan Booth

More information about the Python-list mailing list