On Feb 8, 4:00 am, Duncan Booth <duncan.bo...@invalid.invalid> wrote: > T <misceveryth...@gmail.com> wrote: > > Oops, this one was my fault - the object I was having the issues with > > was actually a shelve file, not a dictionary..so 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 Boothhttp://kupuguy.blogspot.com
Duncan - Thanks for your help. So each of the shelve entries I'm modifying look something like this: myshelve[key] = TestClassObject(param1, param2, param3, param4, param5, etc.). In this case, with quite a few parameters, would you suggest setting writeback=True and just modifying the needed value, or rewriting the entire entry? I have to admit the writeback option looks good, and if the TestClassObject format ever changes (i.e. if I ever change the order of the params), this particular function will be unchanged. However, I don't know what the performance hit would be in using it. -- http://mail.python.org/mailman/listinfo/python-list