What are the differences between _weak_ references and "normal" references?

Jp Calderone exarkun at intarweb.us
Fri Apr 4 19:27:51 CEST 2003


On Fri, Apr 04, 2003 at 09:01:44AM -0800, sdieselil wrote:
> Hi
> 
> I noticed a module weakref in Python standard library. What is weak
> reference and in what way it differs from "normal" reference? 

  Weak references to objects don't increment the refcount for that object.

> By the way, how can I implement usual reference in Python (I mean C++
> reference)?

  You can't, since this requires changing the semantics of assignment.  What
you can do is use wrappers of some form (from the simple, hackish
list-of-length-one to much more complete, OO-style solutions) to move from
name rebinding to attribute modification, giving the same behavior as
C++-style references.

  Jp

-- 
Lowery's Law:
        If it jams -- force it.  If it breaks, it needed replacing anyway.
-- 
 up 15 days, 14:00, 8 users, load average: 0.24, 0.22, 0.09





More information about the Python-list mailing list