03-25-2022 01:25 AM
Hello,
as the title says, I'm wondering if there is a graceful way to exit a python script.
Calling sys.exit / raising SystemExit always seems to trigger an error message, independently of the exit code that is passed. (I tried it with 0, 1, -1, None)
03-25-2022 10:29 AM - edited 03-25-2022 10:29 AM
If I understood it correctly, I think the best way is to use the return command.
def your_function():
# Insert your code here
# .....
# .....
return
03-25-2022 11:01 AM
Hello panta1978,
unfortunately that can only be used within functions.
And execution will continue where the function was called. It will not exit the script.
When used outside of a function it is considered a syntax error.
The script won't even start.