By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,922 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,922 IT Pros & Developers. It's quick & easy.

oddness in shelve module

P: n/a
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 <ms******@digitaltorque.ca>
http://www.digitaltorque.ca
http://opag.ca python -c 'import this'
Jabber: ms******@digitaltorque.ca

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

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

Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Michael P. Soulier wrote:
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"
Jul 19 '05 #2

P: n/a
Michael P. Soulier wrote:
On 22/06/05 John Machin 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):
File "<stdin>", line 1, in ?
TypeError: object does not support item assignment
This is the message that you are thinking about, the word is
"attribute", not "property".
class Dummy: .... pass
.... x = Dummy()
x.dc

Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: Dummy instance has no attribute 'dc'

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.