Python Node Break

Hello All,
Is there a way to drop out of a python node early?
I don’t want to create multiple python nodes that have dependency relationships and I’d like to avoid creating tons of different function definitions. Optimally, I’d like to be able exit the python node in almost a ‘break’ fashion. Is this possible? I have noticed that I can use “sys.exit(0)” but that throws an exception and doesn’t allow me to output what I had computed up to that point. My intent is to save on processing power when computation is unnecessary and to keep the code structure simple by avoiding user-defined functions.

You already pointed out one option - using the break keyword to exit the loop and proceed with the rest of the script:

This is a less than ideal approach because it only escapes the current loop and you might have cases with a nested loop. Plus you always run the risk of forgetting to break from the encapsulating loop.

A much better approach is to restructure your script into functions, because you can return from a function at any point:

image

image

2 Likes