[Python-Dev] Anyone using weakrefs?

Denys Duchier Denys.Duchier at ps.uni-sb.de
Sun Mar 25 00:13:20 CET 2001


"Tim Peters" <tim.one at home.com> writes:

> Still, I've been happily playing w/ this little module:
> 
> import weakref
> id2obj_dict = weakref.mapping()
> 
> def remember(obj):
>     id2obj_dict[id(obj)] = obj
> 
> def id2obj(id):
>     return id2obj_dict.get(id, None)

If memory serves, in T3 (Yale Scheme) the printed representation of an
object included an integer id which you could use as a key to look up
the object in a weak table.  Quite convenient for interactive use.

Cheers,

-- 
Dr. Denys Duchier			Denys.Duchier at ps.uni-sb.de
Forschungsbereich Programmiersysteme	(Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45	http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50			Phone: +49 681 302 5618
66041 Saarbruecken, Germany		Fax:   +49 681 302 5615



More information about the Python-list mailing list