Using weakref with execfile?
exarkun at intarweb.us
Mon Dec 22 01:51:49 CET 2003
On Sun, Dec 21, 2003 at 03:39:43PM +0000, William Trenker wrote:
> 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?
Even if this worked, the dictionary would be empty when execfile()
returned, since nothing would be referencing any of the keys.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 196 bytes
Desc: Digital signature
More information about the Python-list