Calling script in another file

Posted on
Tue Feb 25, 2020 1:54 pm
trevorsmith offline
Posts: 86
Joined: Oct 08, 2016

Calling script in another file

I created a file call abc.py in my docs directory and am trying to call a function in a separate file called def.py , also in the same location.

abc.py contains
import def
blah
myfunc(1)
blah



def.py contains
def myfunc(argumentname):
blah
blah
blah

abc.py is run by a trigger in Indigo, but python fails to find def.py

What am I doing wrong? If I put def.py into Python's site-packages folder then its found but that seems a silly place to put my scripts.

Sorry for the idiot question
Last edited by trevorsmith on Tue Feb 25, 2020 2:47 pm, edited 3 times in total.

Posted on
Tue Feb 25, 2020 2:08 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Calling script in another file

I assume you actually tried that without the comment character and with the correct function name?

abc.py:
Code: Select all
from def import settrv
blah
settrv(1)
blah


def.py:
Code: Select all
def settrv(argumentname):
    blah
    blah
    blah

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Feb 25, 2020 2:31 pm
trevorsmith offline
Posts: 86
Joined: Oct 08, 2016

Re: Calling script in another file

sorry yes, that was a typo

Posted on
Tue Feb 25, 2020 2:36 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Calling script in another file

Rename def.py to __init__.py and put it inside a folder named "def":
Code: Select all
abc.py
def
    __init__.py

Then try it.

How are you testing this? In a terminal session with those files in the current working directory?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Feb 25, 2020 2:38 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Calling script in another file

Actually, before you do that, try:

Code: Select all
import def
blah
def.settrv(1)
blah

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Feb 25, 2020 2:46 pm
trevorsmith offline
Posts: 86
Joined: Oct 08, 2016

Re: Calling script in another file

I have a trigger that invokes the script in abc.py. abc.py gets called fine and runs otherwise as it should. Its just the calling of the function in def.py that's going wrong.

the log file contains

Script Error abc.py: No module named myfunc

Posted on
Tue Feb 25, 2020 2:58 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Calling script in another file

trevorsmith wrote:
I have a trigger that invokes the script in abc.py. abc.py gets called fine and runs otherwise as it should. Its just the calling of the function in def.py that's going wrong.

the log file contains

Script Error abc.py: No module named myfunc


Oh. In that case you need to put the included file (def.py) in a place that Indigo puts in the search path. There's some threads about that in one of the forums. Read this one:

viewtopic.php?f=75&t=23450

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests