Breaking up code into different code modules within Add-in folder

Breaking up code into different code modules within Add-in folder

ebunn3
Advocate Advocate
374 Views
1 Reply
Message 1 of 2

Breaking up code into different code modules within Add-in folder

ebunn3
Advocate
Advocate

Hi,

 

I'm trying to build an Add-in and don't want all of my code within the same code module.  How does one go about creating additional modules that can be imported into the main module?

 

Eric

0 Likes
Accepted solutions (1)
375 Views
1 Reply
Reply (1)
Message 2 of 2

ebunn3
Advocate
Advocate
Accepted solution

I've figured this out:

 

It has to do with using Relative Imports.  I used the following import statements successfully to import functions and classes from other modules contained both in the parent folder and sub folders.  I have attached a sample directory of files.

 

Eric

#Relative Imports
#import module from within same folder
from . import TestScript3_Class as cls3
#import module from sub folder
from .Tests import TestScript2 as ts
from .Tests import TestScript2_Class as cls
#import a specific function from a nested folder (use the dot like a \ in a file path )
from .Tests.TestsCopy.TestScript2 import Test

 

 

 

Eric