I have two files: parent.py and child.py. I wish to use the parent to run the child script, but I want the displays within the child script to appear in the console window. Example files are below:
child.py:
from scipy import optimize
x0=1
def f(x):
return x**2
res = optimize.fmin(f, x0, disp=True)
print('print printed')
parent.py:
import subprocess
subprocess.run(["python", "child.py"], capture_output=True)
My understanding was that the capture_output
option should display the output as desired, but this does not appear to be the case. (This comes from the comment reply on my question Consecutively execute multiple python scripts which I am trying to ask here in a clearer way).
Both parent and child files are located within the same working directory, and I am using Spyder (not sure if that matters). I see what makes me think the child file is running In: runfile('C:/.../parent.py', wdir='C:/.../testing')
, but I see neither the print() command nor the display from the optimize command displayed in my console. I also do not have access to the child variables once I have run the parent.
How do see the outputs (from print() and the optimize(.,disp=True) commands), as well as access the variables in the child script when running the parent?