Splitting the code into modules


for the sake of improving readability I wanted to put some useful functions that I write and frequently call into another file.py and only import and use them inside the slicer module code (inside widget or logic).
But for some reason it doesn’t work properly, and whenever I update the function in my file.py, I need to restart slicer so the slicer module can see and use the changes I made.
Any ideas?


If you have developer mode enabled and your module UI has the default ״Reload module” button- press it every time you edit your script so that only the module is reloaded and not the whole slicer.
Hope this helps

1 Like

The reload button only knows about your module.py file. You need to add reloading of any additional files. See example in SlicerHeart extension. Note that if you have a complex dependency between multiple files then you need to reload the files in the correct order (or else you may need to click reload a few times).

1 Like