When you are working on anything but a very simply python script it is usually better to write it in a dedicated IDE rather than try to work exclusively in the Nuke script editor. But it can be a bit of a pain to test your code in Nuke if you are writing it in a different program. It usually involves copying and pasting code from the editor to Nuke, then running it, and if you make and changes in the Nuke script editor, copying them back to the IDE.
I have been using Atom for my IDE which has a Nuke extension that allow you to run code directly from Atom in an open Nuke session, you can read more about that here.
You can also save your script, setup your menu.py file to import it, and then launch Nuke and it will import your script read to run. The problem with this approach is that you have to quit Nuke and relaunch it whenever you make changes to your script. Or so I thought until I learned about the reload function.
Before Nuke 13 Nuke used Python 2.7. In this version of Python you could simply use
reload() to reload modules that Nuke had already loaded, but that had changed since. So in the Nuke script editor you could simply run the following line after you saved a change to your external .py file:
But when I tried this in Nuke 13 the other night it didn’t work. Nuke 13 has moved from Python 2.7 to Python 3.7.7 After a quick search I discovered that in Python 3 the reload function is now part of the importlib library that has to be imported separately. So to reload a module in Nuke 13 you need:
import importlib importlib.reload(myModule)
Just keep that in you Nuke script editor and run it every time you save the .py file you are working on and the changes will be updated inside Nuke.