Matthias Bussonnier wrote:
I search for a method
capable of telling me whether an object can be weakreferenced.
Objects that can be weakly referenced have a __weakref__ attribute.
So you could use hasattr(obj, '__weakref__').
--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
On Tuesday 13 December 2016 15:57, Matthias Bussonnier wrote:
[...]
> I could of course write a function that try/except and return False/True
> depending on the result, but that seem suboptimal as how can I know that the
> TypeError does come from not being able to take a weak reference ? And
Hi all,
I was recently had to use weakreferences, using the weakref module, and came
across the fact that some object cannot be weakreferenced. If you try to do so
you get greated by a TypeError, which is a totally expected and documented
behavior.
As I tend to prefer the "Look before you