Re: [Tutor] object's attributes

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 1:36 PM, Paul McGuire wrote: > The example you cited of creating a thin derived class from object, for the > simple purpose of supporting dynamically assigned attributes, sometimes goes > by the name Bag, from the Smalltalk object framework. Another variation is Bunch, tho

Re: [Tutor] object's attributes

2009-01-02 Thread spir
On Fri, 2 Jan 2009 12:36:42 -0600 "Paul McGuire" wrote: > Denis - Hello Paul, pleased to read you again ;-) > What you are seeing is standard procedure for any built-in type - no dynamic > assignment of attributes allowed. Here is an analogous case to your > example, but based on str instead

Re: [Tutor] object's attributes

2009-01-02 Thread Paul McGuire
Denis - What you are seeing is standard procedure for any built-in type - no dynamic assignment of attributes allowed. Here is an analogous case to your example, but based on str instead of object: greeting = "bon jour" greeting.language = "French" # raises AttributeError: 'str' object has no a

Re: [Tutor] object's attributes

2009-01-02 Thread Kent Johnson
On Fri, Jan 2, 2009 at 11:10 AM, spir wrote: > Can someone explain the following? > > > class Type(object): >pass > o = Type() > o.a = 1 > print o, o.a > print dir(object) > ==> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', > '__init_

Re: [Tutor] object's attributes

2009-01-02 Thread Alan Gauld
"spir" wrote Can someone explain the following? Not really an explanation but I did notice when repeating your experiment that your class instance has a __dict__ attribute but object does not. The new attribute a is apparently located in the dict. class C(object): pass ... o = object() c

[Tutor] object's attributes

2009-01-02 Thread spir
Can someone explain the following? class Type(object): pass o = Type() o.a = 1 print o, o.a print dir(object) ==> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setat