Could an object delegate itself into another?

Fred L. Drake, Jr. fdrake at acm.org
Fri Oct 22 14:13:07 EDT 1999


François Pinard writes:
 > Quite interesting.  So you are saying that the implementation of an instance
 > is fully held in its __dict__?  That would be simple enough, then...

  Not quite, as another poster pointed out.  The two objects wouldn't
even be == unless you wrote a .__cmp__() method that did the right
thing.  You'd probably also want to write a .__hash__() that did the
right thing as well, since the default hash wouldn't "do the right
thing" any more.

 > >   Not to be used in real code!
 > 
 > Yet if you are right, this is exactly the functionality I was looking for.
 > What else, then?  I do agree that `self.__dict__ = some.__dict__' might look
 > tinily odd within an `__init__' function, at least until I get used to it :-)

  I wasn't serious; I think the factory function with a cache is the
'right' way to do it; this is just nasty hackery that I thought a
little cute, in an evil sort of way.  You want the factory function.


  -Fred

--
Fred L. Drake, Jr.	     <fdrake at acm.org>
Corporation for National Research Initiatives




More information about the Python-list mailing list