Re: Question about weakref

Discussion in 'Python' started by Frank Millman, Jul 5, 2012.

  1. On 05/07/2012 10:46, Dieter Maurer wrote:
    > Frank Millman<> writes:
    >
    >> I have a situation where I thought using weakrefs would save me a bit
    >> of effort.

    >
    > Instead of the low level "weakref", you might use a "WeakKeyDictionary".
    >


    Thanks, Dieter. I could do that.

    In fact, a WeakSet suits my purposes better. I tested it with my
    original example, and it works correctly. It also saves me the step of
    deleting the weak reference once the original object is deleted, as it
    seems to do that automatically.

    I just need to double-check that I would never have the same
    listener-object try to register itself with the publisher twice, as that
    would obviously fail with a Set, as it would with a Dict.

    I would still like to know why weakref.proxy raised an exception. I have
    re-read the manual several times, and googled for similar problems, but
    am none the wiser. Naturally I feel a bit uneasy using a feature of the
    language which sometimes fails mysteriously, so if anyone has an
    explanation, I would really appreciate it.

    Frank
    Frank Millman, Jul 5, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank Millman

    Question about weakref

    Frank Millman, Jul 4, 2012, in forum: Python
    Replies:
    0
    Views:
    166
    Frank Millman
    Jul 4, 2012
  2. Dieter Maurer

    Re: Question about weakref

    Dieter Maurer, Jul 5, 2012, in forum: Python
    Replies:
    0
    Views:
    178
    Dieter Maurer
    Jul 5, 2012
  3. Dieter Maurer

    Re: Question about weakref

    Dieter Maurer, Jul 5, 2012, in forum: Python
    Replies:
    0
    Views:
    163
    Dieter Maurer
    Jul 5, 2012
  4. Frank Millman

    Re: Question about weakref

    Frank Millman, Jul 6, 2012, in forum: Python
    Replies:
    0
    Views:
    152
    Frank Millman
    Jul 6, 2012
  5. Ian Kelly

    Re: Question about weakref

    Ian Kelly, Jul 6, 2012, in forum: Python
    Replies:
    0
    Views:
    159
    Ian Kelly
    Jul 6, 2012
Loading...

Share This Page