oddness in shelve module

M

Michael P. Soulier

I'm trying to add objects to a shelve db object via hash assignment, but
I'm getting an odd exception.

Traceback (most recent call last):
File "RemGui.py", line 117, in onMonitorButton
self.startMonitoring()
File "RemGui.py", line 163, in startMonitoring
self.monitor()
File "RemGui.py", line 181, in monitor
self.db.store_sample(dbentry)
File "C:\Documents and Settings\Michael Soulier\My
Documents\projects\rem\pysr
c\RemDBShelve.py", line 38, in store_sample
self.db[sample.timestamp] = sample
TypeError: object does not support item assignment

The object itself is quite simple.

I provide it below. If anyone can shed light on this, I'd appreciate it.

Thanks,
Mike

class RemDBEntry(object):
"""This class represents one entry in the database. It stores a
merging of all of the document types supplied by the server."""

def __init__(self, timestamp):
self.timestamp = timestamp
self.procs = []
self.partitions = []
self.free = None
self.uptime = None

def merge(self, doc):
"""This method takes a RemDoc object and merges it with the
current object."""

if doc.type == 'uptime':
self.uptime = doc.scalar
elif doc.type == 'ps':
self.procs = doc.children
elif doc.type == 'siloShow':
self.partitions = doc.children
elif doc.type == 'siloShowMaxFree':
self.free = doc.scalar
else:
raise AssertionError, "Unknown document type: %s" % doc.type


--
Michael P. Soulier <[email protected]>
http://www.digitaltorque.ca
http://opag.ca python -c 'import this'
Jabber: (e-mail address removed)

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQFCuMwfKGqCc1vIvggRAm/lAKCwIs4ARhlHHMIrIqLxuWSEW4bYCQCgmfTt
rJuF+R+8ZFYBMeGwDzzXx8o=
=21xf
-----END PGP SIGNATURE-----
 
J

John Machin

Michael said:
I'm trying to add objects to a shelve db object via hash assignment, but
I'm getting an odd exception.

Traceback (most recent call last):
File "RemGui.py", line 117, in onMonitorButton
self.startMonitoring()
File "RemGui.py", line 163, in startMonitoring
self.monitor()
File "RemGui.py", line 181, in monitor
self.db.store_sample(dbentry)
File "C:\Documents and Settings\Michael Soulier\My
Documents\projects\rem\pysr
c\RemDBShelve.py", line 38, in store_sample
self.db[sample.timestamp] = sample
TypeError: object does not support item assignment

The object itself is quite simple.

I provide it below.

AFAICT, wrong "it". The "item assignment" which is alleged not to be
supported is of this form: an_object[some_key] = a_value

I.e. "self.db" is the suspect, not "sample"
 
J

John Machin

Michael said:
AFAICT, wrong "it". The "item assignment" which is alleged not to be
supported is of this form: an_object[some_key] = a_value

I.e. "self.db" is the suspect, not "sample"

Ah. Let me test that it is in fact being created properly then. I
expected an error more like, "object has no property db" in that case.

Mike
sorry, perhaps I wasn't clear enough -- you seem to think I meant "self"
has no attribute called "db". No, "self.db" exists, but it doesn't
support the activity of assigning to an indexed item, like a dictionary.

The interactive interpreter is your friend:
>>> adict = {}
>>> adict[3] = 4
>>> notlikeadict = 666
>>> notlikeadict[3] = 4
Traceback (most recent call last):

This is the message that you are thinking about, the word is
"attribute", not "property".
.... pass
....Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: Dummy instance has no attribute 'dc'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,930
Messages
2,570,072
Members
46,521
Latest member
JamieCooch

Latest Threads

Top