how to achive - file write open on __del__?

后端 未结 4 560
予麋鹿
予麋鹿 2021-01-22 18:40

I m trying to do a some activity on class obj destruction. How do I achive file open in _del__ function? (I m using Python 3.4)

class iam(object):

    def __in         


        
4条回答
  •  旧巷少年郎
    2021-01-22 19:36

    As others have mentioned, don't use the ____del___ method to perform such cleanup. Instead, use either contextmanagers (with-statement) or register atexit-handlers.

提交回复
热议问题