weakrefs to functions for observer pattern
Michael Schneider
michaelschneider at fuse.net
Thu Nov 3 09:55:06 EST 2005
Alex Martelli wrote:
> Michael Schneider <michaelschneider at fuse.net> wrote:
>
>
>>I would like to use weak refs in an observer pattern implementation.
>>The problme that I have seems to be that weakrefs can't manage functions.
>
>
> They can manage just fine functions written in *Python*, just not
> "builtin functions*, i.e., ones written in *C*. Just wrap any builtin
> function you need to register as observer into a tiny Python-coded
> wrapper and live happily ever after.
> ...
>
>>Not all objects can be weakly referenced; those objects which can
>>include class instances, functions written in Python (but not in C),
>
>
>
> Alex
Alex,
Thank you, I mis-read the docs.
The mistake I made was having was using a weak reference as a key in
the dictionary.
Weak references will be very useful for me.
I really enjoy python. So many good things have been added to the
language without taking the fun away :-)
Mike
--
The greatest performance improvement occurs on the transition of from
the non-working state to the working state.
More information about the Python-list
mailing list