0

I have this script:

from myhelperfunctions import *
# parse arguments
args = docopt(__doc__, version='mainprog 1.0')
myhelper1(args)
...

This is a script someone else maintains and I have no control over, so i cant modify it. The script structure looks like /opt/app-to-import/{main.py, myhelperfunctions.py}

I want to run this code in another program in my home directory, but don't want to start a new process. so I tried exec() and imp.load_source() to load and run it inside the same process. But every time it complains saying no module named myhelperfunctions. What is the right way to do this? I am using python2.7.

suppandi g
  • 446
  • 5
  • 15
  • Both `exec` and `load_source()` are not things you want to use unless you have to. If you just import the script then all top level statements will run. Alternatively wrap the code of interest in a function and call it. – Alex Hall Sep 25 '15 at 20:15
  • If you add `/opt` to your `PYTHONPATH` and `import main` what happens? – Alex Hall Sep 25 '15 at 20:32

0 Answers0