oddness in shelve module

John Machin sjmachin at lexicon.net
Wed Jun 22 15:35:37 EDT 2005


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'




More information about the Python-list mailing list