Import modules in 1 python script and use that module in the 2nd python script

50 Views Asked by At

I have 2 python scripts (say script1.py and script2.py). I want to import a module (say NumPy) once in script1 and then use that loaded module in script2. I am doing this to save the package loading time for the same script again and again. There are a few modules which take almost 20-30 sec to load every time I execute a script. I want to call script2 from script1 in an infinite loop.

script1.py:

import numpy
import os
for i in range(10):
    os.system('python3 script2.py --function'+numpy)

script2

parser = argparse.ArgumentParser()
parser.add_argument('--function', help='numpy function')
args = parser.parse_args()
a = args.function.asarray(some_data)
print(a)
0

There are 0 best solutions below