How to exit from a Python code?



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?



(Graham) #3

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

if __name__ == ‘__main__’:

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