Using weakref with execfile?

Jp Calderone exarkun at intarweb.us
Sun Dec 21 19:51:49 EST 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.

  Jp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: Digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20031221/2e176627/attachment.sig>


More information about the Python-list mailing list