Using weakref with execfile?

William Trenker wtrenker at shaw.ca
Sun Dec 21 10:39:43 EST 2003


I'm trying to use a weak reference with execfile, if that even makes sense.  The following snippet produces an execption:

Python 2.3.2 (#1, Oct 27 2003, 10:19:56) 
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import weakref
>>> d=weakref.WeakKeyDictionary()
>>> execfile('x.py',d)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: execfile() argument 2 must be dict, not instance

I've read the weakref docs.  I thought maybe the weakref.ref or weakref.proxy functions might be needed but they also return their own types which are, of course, not "dict" and so make execfile unhappy.

Am I doing something wrong with weakref, or is it even possible to use a weak reference dict with execfile?

Thank you,
Bill





More information about the Python-list mailing list