object aware of others

Terry Reedy tjreedy at udel.edu
Sun Jan 29 00:12:28 EST 2012


On 1/28/2012 11:02 PM, Chris Angelico wrote:
> On Sun, Jan 29, 2012 at 2:48 PM, Lee Chaplin<lchaplin13 at gmail.com>  wrote:
>> I am trying to create an object that is aware of other objects created
>> before itself, and when found, then copy some attributes from them,
>> something like:
>
> If you're looking only at other objects of the same class, the easiest
> way is to maintain a list every time one is created. Then you just
> iterate over that list to know about your friends.
>
> To do this, just append to the list in __init__, and possibly have an
> explicit "destroy" or "remove" method that will take self out of that
> list.

Sets are much better for removal.

-- 
Terry Jan Reedy




More information about the Python-list mailing list