# Importing and using class from .py into a custom scripted module

**URL:** <https://discourse.slicer.org/t/importing-and-using-class-from-py-into-a-custom-scripted-module/11221>\
**Category:** Development\
**Created:** [April 21, 2020, 9:21am UTC](https://discourse.slicer.org/t/importing-and-using-class-from-py-into-a-custom-scripted-module/11221 "2020-04-21T09:21:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![laura.gelcano](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@laura.gelcano](https://discourse.slicer.org/u/laura.gelcano)\
**Post date:** [April 21, 2020, 9:21am UTC](https://discourse.slicer.org/t/importing-and-using-class-from-py-into-a-custom-scripted-module/11221/1 "2020-04-21T09:21:23Z")

</div>

Hello,

I am using Slicer 4.11.0 on a Windows 10 computer and developing a Python scripted module.

I want to import a class (TripleMRNet from TripleMRNet.py) from my scripted module, so that I can use it in the module. This TripleMRNet.py is in the same directory as the scripted module.

I have tried to import the class directly in the Python Console and it runs well:

 ![load_fromPythonIterator](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/8/b8b5d298dbb8dc2f16da4d5e70d84414ac722e54.jpeg)

However, when I tried to use it in my scripted module I get the following error:  
AttributeError: Can’t get attribute ‘TripleMRNet’ on \<module ‘ **main** ’ (built-in)\>

![load_fromScriptedModule](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/4/b48e2d930538ae18454f657dcd5e29e23a1d7629.jpeg)

Any help is appreciated.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 21, 2020, 3:34pm UTC](https://discourse.slicer.org/t/importing-and-using-class-from-py-into-a-custom-scripted-module/11221/2 "2020-04-21T15:34:52Z")

</div>

> [@laura.gelcano](#):
>
> This TripleMRNet.py is in the same directory as the scripted module.

Slicer expects all .py files in a scripted module folder to be Slicer module, so you need to put all additional files into regular [Python packages](https://realpython.com/python-modules-packages/#python-packages) in subfolders. See [Extension wizard module](https://github.com/Slicer/Slicer/tree/master/Modules/Scripted/ExtensionWizard) and its ExtensionWizardLib package as an example.

The only complication is that you need to implement dynamic reloading of custom packages, if you want to reload your module without restarting Slicer. See this post for details: [Python scripted module development reload feature for multiple files - #4 by lassoan](https://discourse.slicer.org/t/python-scripted-module-development-reload-feature-for-multiple-files/6363/4)

---

<div class="post-metadata">

**Author:** ![laura.gelcano](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@laura.gelcano](https://discourse.slicer.org/u/laura.gelcano)\
**Post date:** [April 22, 2020, 10:56am UTC](https://discourse.slicer.org/t/importing-and-using-class-from-py-into-a-custom-scripted-module/11221/3 "2020-04-22T10:56:14Z")

</div>

Thank you so much, now it works perfectly.
