Please help with MemoryError

Tim Chase python.list at tim.thechases.com
Fri Feb 12 09:54:27 EST 2010


Aahz wrote:
>>> Not quite.  One critical difference between dbm and dicts
>>> is the need to remember to "save" changes by setting the
>>> key's valud again.
>> 
>> Could you give an example of this?  I'm not sure I
>> understand what you're saying.
> 
> Well, you're more likely to hit this by wrapping dbm with shelve (because
> it's a little more obvious when you're using pickle directly), but
> consider this:
> 
>     d = anydbm.open(DB_NAME, "c")
>     x = MyClass()
>     d['foo'] = x
>     x.bar = 123
> 
> Your dbm does NOT have the change to x.bar recorded, you must do this
> again:
> 
>     d['foo'] = x
> 
> With a dict, you have Python's reference semantics.

Ah, that makes sense...fallout of the "dbm only does string 
keys/values".  It try to adhere to the "only use strings", so I'm 
more cognizant of when I martial complex data-types in or out of 
those strings.  But I can see where it could bite a person.

Thanks,

-tkc







More information about the Python-list mailing list