kseehof at neuralintegrator.com
Fri Sep 28 01:35:00 CEST 2001
> Ken Seehof wrote:
> > >>> sys.version
> > '2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)]'
> > >>> import weakref
> > >>> d = weakref.WeakValueDictionary()
> > >>> d['z']
> > Traceback (most recent call last):
> > File "<input>", line 1, in ?
> > File "C:\PYTHON21\lib\weakref.py", line 35, in __getitem__
> > o = self.data.get(key)()
> > TypeError: object of type 'None' is not callable
> > Shouldn't this be raising KeyError instead of TypeError?
> Probably :)
> While we are at it, I would like to see the ability to have a weak-ref
> to None - this would allow me to remove special casing for None in the
> places I have used weakrefs to date.
> But-that-is-a-different-problem ly,
Well here's how I got around the weak None thing:
Then you can say x=NoneRef and x will act like a weak-ref to None.
(yeah, I know return None is the same as pass, but I like being explicit)
More information about the Python-list