Can we create an_object = object() and add attribute like for a class?

Alex Martelli aleaxit at yahoo.com
Sat Apr 29 19:26:16 EDT 2006


Pierre Rouleau <prouleau at impathnetworks.com> wrote:
   ...
> I can understand the design decision not to give object a __dict__, but
> I wonder if i'd be a good idea to have a class that derives from object
> and has a __dict__ to be in the standard library.  I posted the original
> question because I run into this quite often and I just saw a post a 
> little before mine ("self modifying code") where the idiom was used.

Yes, I do agree it would be a good idea.  It's probably too late to add
features to Python 2.5, but I think you should propose a PEP for 2.6.
Standard library module containers seems to be a good place for the
proposed namespace-type, but some discussion might help get some idea of
a consensus about the type's name (is 'namespace' good enough?  Is an
__init__ taking arbitrary named arguments, and a __repr__ emitting them,
all the functionality we need -- or should perhaps the type also expose
some other methods delegating to the underlying __dict__, such as
__len__ [[number of attributes]], update, __contains__, __iter__...?).


Alex



More information about the Python-list mailing list