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
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
© 2024 OneMinuteCode. All rights reserved.