-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Splitting code in subfolder #40
Comments
I have asked the 3D Slicer forum. Here is one answer: https://discourse.slicer.org/t/slicer-development-code-fragmentation/38516/3
|
Hi, Issue 40 will be solved soon in @AcastaPaloma pull requests. In addition, we found and tested how to use/split the code in different files in a subFolder. Example of organization: On the same level than the file SlicerCART.py (main script file), an additional folder is created (ie, subfolder), which contains one or multiple python files that have content to be re-used in the main script (SlicerCART.py file). In the main .py file (e.g. SlicerCART.py), you use the following syntax: In a child python file (e.g. SlicerConfigurationWindow.py), you can insert your functions that you want to use in the main python script. You can also import the content of another child python file in the same subfolder by doing *Note that Slicer python interpreter will always consider the path from the main python file associated with the module. This means that if you want to import a child python file at the same level than another python file, you must specify the location according to the main python file. For example: to import subFolder.CheckFunctions.py in subFolder.SlicerConfigurationWindows.py, you must write In each child python file (e.g. CheckFunctions.py), it is recommended to add the following imports:
Thanks. |
Thanks for your investigation. This seems to be the standard Python way of modularizing code. Is there any specific item besides adding the 2 lines you mentioned at the end of your post ? Few questions:
|
Is your feature request related to a problem? Please describe.
The main script is too long.
Describe the solution you'd like
While the ideal solution would be to split the code in subfolders/modules, my attempts to make it work in Slicer always end up with
ModuleNotFoundError
. This is usually easy to perform in standard Python scripts but not through Slicer. There is a post about this here but I was not able to make it work even after updating the path like so:The text was updated successfully, but these errors were encountered: