What is the difference between a static method and class method in Python?

How do I properly manage the Python class __del__(self) method process?

  • I created a class using a module that saves run-time data within an instance dictionary object.  At the end of the process I'd like to serialize this dictionary object to a file using cpickle, which I do in the __del__(self) method.  Often times however Python begins the destruction process before __del__(self) is called and deletes the dictionary object before I can serialize it.  How do I address this occurrence?

  • Answer:

    Turn it into a regular save method and then register an exit handler to call that method when the process intends to exit. http://docs.python.org/library/atexit.html

Kevin Matzen at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.