Python attributeError on __del__

前端 未结 2 1444
执念已碎
执念已碎 2020-12-01 17:06

I have a python class object and I want to assign the value of one class variable

class Groupclass(Workerclass):
    \"\"\"worker class\"\"\"
    count = 0

         


        
2条回答
  •  天涯浪人
    2020-12-01 17:19

    When __del__() method called, the Groupclass may be recovered by the garbage collection mechanism, so using Groupclass.xxx may failed. But you can access the count variable through self.__class__.count. Code likes below:

    def __del__(self):
        self.__class__.count -= 1
    

提交回复
热议问题