How Python last executes and terminates certain code at the end of a program

Asked 2 years ago, Updated 2 years ago, 18 views

I don't want to end the program immediately at the end of the program on Python, but I want to end it after executing a specific code. Is this possible?

For example, when you close the process window or run and exit the py file from the terminal, or when the program ends, print out hello world and exit

Actually, it's not for printing hello world and ending it.

We're going to save a specific log to a variable and then use file input/output when the program ends to save the contents of the variable to a text file and implement the program ending.

python

2022-09-22 18:00

1 Answers

The associated modules are provided.

Of course, it is only possible at the normal end. Forced termination of a process is not a possible range.

https://docs.python.org/ko/3/library/atexit.html


2022-09-22 18:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.