# Split large python script into smaller files

**URL:** <https://discourse.slicer.org/t/split-large-python-script-into-smaller-files/38516>\
**Category:** Development\
**Created:** [September 24, 2024, 12:57pm UTC](https://discourse.slicer.org/t/split-large-python-script-into-smaller-files/38516 "2024-09-24T12:57:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximeb](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@maximeb](https://discourse.slicer.org/u/maximeb)\
**Post date:** [September 24, 2024, 12:57pm UTC](https://discourse.slicer.org/t/split-large-python-script-into-smaller-files/38516/1 "2024-09-24T12:57:23Z")

</div>

Hi!

Our team is developing a 3D Slicer module.

However, we are unable to fragment the code that is used so our script has now more than 3 000 lines in one python script (and we would like to have for example 10 python scripts of 300 lines that make working the module we are developing for example). How can we fragment a python script into multiple files of a 3D Slicer module code?

Thank you in advance for considering this aspect,

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [September 24, 2024, 1:04pm UTC](https://discourse.slicer.org/t/split-large-python-script-into-smaller-files/38516/2 "2024-09-24T13:04:34Z")

</div>

You can split the code into different files and put them in a lib directory. See for example how this is one in the DICOM module and the [DICOMLib directory](https://github.com/Slicer/Slicer/tree/main/Modules/Scripted/DICOMLib).

---

<div class="post-metadata">

**Author:** ![maximeb](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@maximeb](https://discourse.slicer.org/u/maximeb)\
**Post date:** [September 24, 2024, 1:07pm UTC](https://discourse.slicer.org/t/split-large-python-script-into-smaller-files/38516/3 "2024-09-24T13:07:34Z")

</div>

Ok thanks for your quick answer! It is greatly appreciated!  
Cheers,
