Importing python files from different bases

Hi Everyone,

Stuck on understanding how the following works:

I have two bases with the Global OP Shortcuts BASE1 and BASE2.

In each base there’s a python file (python1 and python2). I want to import the python file from BASE1 into the python file in BASE2. When I try to do it I get the error: ModuleNotFoundError: No module named ‘python1’.

I’m guessing this is because the bases are in two different levels so the python files can’t see each other. Is there a method that’s usually used for this?

Here’s a quick demo file.
import_python.toe (3.7 KB)

Thanks

python1 = op.BASE1.op('python1').module

or

python1 = op.BASE1.mod.python1
1 Like

perfect, thanks Ivan!

Be careful with the “mod” object. It will search upward for a module with that name. If you want to guarantee the specific DAT, use the .module method.

Okay, got it. Will do.

If python1 isn’t in a base and is just in the project1 container, do I need to give the project1 container a Global OP Shortcut and do the following:

python1 = op.P1SHORTCUT.op(‘python1’).module ?

I tried that but got the ModuleNotFoundError again.

Actually, it works if I do:

python1 = op.P1SHORTCUT.mod.python1

but not:

python1 = op.P1SHORTCUT.op('python1').module

I must be mixing something up, I’ll keep digging.