How to exit from a Python code?

#1

Hello,

If your code is written in a GHPython node, is there a way to exit from the code in the middle of the code?
You can exist from a function by “return”.
You can exit from a for loop by “break”
Buf when your code is at the top level, how to exit?

#2

Try
exit()

(Graham) #3

Or put all your code in a main() function and return to exit : this is good practice in Python

if __name__ == ‘__main__’:
    main()
#4

Thank you both.
Seems like exit() does not work for GHPython node. I’ll try making a main() function.