Re: Question about weakref

2012-07-06 Thread Frank Millman
On 06/07/2012 20:12, Ethan Furman wrote: Ian Kelly wrote: def del_b(self, b): for i, x in enumerate(self.array): if b is x: del self.array[i] break Nice work, Ian. I second that. Thanks very much, Ian. Frank -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about weakref

2012-07-06 Thread Ethan Furman
Ian Kelly wrote: def del_b(self, b): for i, x in enumerate(self.array): if b is x: del self.array[i] break Nice work, Ian. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about weakref

2012-07-06 Thread Ian Kelly
On Fri, Jul 6, 2012 at 11:48 AM, Ian Kelly wrote: > def del_b(self, b): > for i, x in enumerate(self.array): > if b is x: > del self.array[i] That should probably have an explicit break on the end: def del_b(self, b): for i, x in enumerate(self

Re: Question about weakref

2012-07-06 Thread Ian Kelly
On Fri, Jul 6, 2012 at 11:04 AM, Ian Kelly wrote: > On that, I'm really not sure. I tried to reproduce the problem > locally and wasn't able to. What build of Python are you using, and > on what platform? I spoke too soon, I am able to reproduce it. I think what's going on here is that when yo

Re: Question about weakref

2012-07-06 Thread Ian Kelly
On Fri, Jul 6, 2012 at 1:00 AM, Frank Millman wrote: > I have investigated a bit further, and now I have a clue as to what is > happening, though not a full understanding. > > If you use 'b = weakref.ref(obj)', 'b' refers to the weak reference, and > 'b()' refers to the referenced object. > > If y

Re: Question about weakref

2012-07-06 Thread Frank Millman
On 05/07/2012 19:47, Dieter Maurer wrote: Frank Millman writes: 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. In fact, it is documented. Accessing a proxy will raise an excep

Re: Question about weakref

2012-07-05 Thread Dieter Maurer
Frank Millman writes: > On 05/07/2012 10:46, Dieter Maurer wrote: >> 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

Re: Question about weakref

2012-07-05 Thread Frank Millman
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

Re: Question about weakref

2012-07-05 Thread Dieter Maurer
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". -- http://mail.python.org/mailman/listinfo/python-list