Could an object delegate itself into another?

François Pinard pinard at IRO.UMontreal.CA
Thu Oct 21 20:12:52 EDT 1999


"Fred L. Drake, Jr." <fdrake at acm.org> écrit:

> François Pinard <pinard at iro.umontreal.ca> writes:
>  > But yet, I wonder.  Could an object really delegates itself into
>  > another?  For example, is there some way by which a newly created
>  > object could soon check, probably within __init__, if a similar copy
>  > has already been registered?

> 	>>> class C: pass
>         ...
>         >>> c1 = C()
>         >>> c2 = C()
>         >>> c2.__dict__ = c1.__dict__
>         >>> c1.foo = "bar"
>         >>> c2.foo
>         'bar'

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 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 :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list