在Python中更改对象引用计数时是否运行魔术方法

时间:2017-11-12 21:21:35

标签: python

我想要一个在更改对象引用计数时运行的方法。是否有类似以下代码的方法?

class Foo():
    def __method__(self):
        print("ojbect reference count is changed !")

a = Foo()
b = a  # runs __method__ because the reference count is increased
c = b  # runs __method__ because the reference count is increased
del b  # runs __method__ because the reference count is decreased
del c  # runs __method__ because the reference count is decreased

感谢。

0 个答案:

没有答案