# Sharing python code between (scripted loadable) modules

**URL:** https://discourse.slicer.org/t/sharing-python-code-between-scripted-loadable-modules/24921
**Category:** Development
**Created:** [August 25, 2022, 1:30pm UTC](https://discourse.slicer.org/t/sharing-python-code-between-scripted-loadable-modules/24921 "2022-08-25T13:30:27Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![talmazov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/talmazov/32/3966_2.png) [@talmazov](https://discourse.slicer.org/u/talmazov)
#### Post date: [August 25, 2022, 11:07pm UTC](https://discourse.slicer.org/t/sharing-python-code-between-scripted-loadable-modules/24921/3 "2022-08-25T23:07:48Z")

</div>

Hey,  
I should chime-in since you referenced a topic I posted previously. In my case I have a custom library that was shared by two separate applications - a TCP/IP socket class. Let’s call it `sock.py`  
to use sock.py in a slicer scripted module I had to setup the directory structure as so

```auto
WidgetRootDir
 |
 | - slicerWidget.py
 | - subdirectory
      | - __init__.py
      | - sock.py

```

` __init__.py` contains

> from .sock import \*

And slicerWidget.py imports as so

> from subdirectory import sock

If you need to access another slicer module this is a clean way of doing so [Setting widget variable from --python-code on Slicer.exe start - #13 by talmazov](https://discourse.slicer.org/t/setting-widget-variable-from-python-code-on-slicer-exe-start/23908/13)

I hope this helps

~ Georgi

---

_[View the full topic](https://discourse.slicer.org/t/sharing-python-code-between-scripted-loadable-modules/24921)._
