Is it really OK to do object closeing/disposing in __del__?

前端 未结 3 1562
没有蜡笔的小新
没有蜡笔的小新 2021-01-05 05:04

I have been thinking about how I write classes in Python. More specifically how the constructor is implemented and how the object should be destroyed. I don\'t want to rely

3条回答
  •  耶瑟儿~
    2021-01-05 05:31

    Not necessarily. You'll encounter problems when you have cyclic references. Eli Bendersky does a good job of explaining this in his blog post:

    • Safely using destructors in Python

提交回复
热议问题