1. property
class C():
def SetIt(self):
self.a = 1
def GetIt(self):
return self.a
content = property(SetIt, GetIt)
c = C()
c.content = 1
print c.content # will print 1
2. id
id(1) # this is a number..
3. weakref
import weakref
class C():
def func(self):
pass
c = C()
c.func()
p = weakref.proxy(c)
p.func()
r = weakref.ref(c)
r().func()
import weakref
_id2obj_dict = weakref.WeakValueDictionary()
def remember(obj):
oid = id(obj)
_id2obj_dict[oid] = obj
return oid
def id2obj(oid):
return _id2obj_dict[oid]