opposite of __init__.py

T

Tamer Higazi

Hi people!

I have asked myself a question, if there is a opposite of "__init__.py"
like "__del__.py" ?!

I want, that when the application ends, certain functions are executed.
I know I could make a constructor and a destructor, but I simply want to
know if there is a opposite....


Thanks



Tamer
 
S

Steven D'Aprano

Hi people!

I have asked myself a question, if there is a opposite of "__init__.py"
like "__del__.py" ?!

No. If you want to run code when your application is shutting down, run
it just before your code finishes:

def main():
do_this()
do_that()


if __name__ == '__main__':
main()
shutdown()


If you care about code running even if an exception takes place:


if __name__ == '__main__':
try:
main()
finally:
shutdown()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top