Link to home
Start Free TrialLog in
Avatar of m_travis
m_travisFlag for United States of America

asked on

Return data from python script to another python scrip

I would like to call a python script from a different python script and pass the data back to the original on a windows machine.

Main python Script:
import OtherPythonScript

results = Execute OtherPythonScript

OtherPythonScript
do x:
    record results to y

return y
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think @pepr solution will work if you can change your script into a function, but I think this may not be your final solution depending on your requirements.

Maybe a little more context on your problem could help us to direct you better.
A little context would help to give the right advice for your case.

My first impression is, that for most cases pepr gave exactly the right answer. (especially if the script that you want to call is under your control). Just import and call the function


Some options you have are:
1) import the python script as module and execute the functions required (pepr's suggestion if you can modify the code)
2) Same as above but start in a separate thread
3.) import the other module and use the multiprocessing module for data exchange
3.) start script as a subprocess, collect it's stdout
4.) start the other script / process, write the results to a file and read the file when the script is finished
5.) start the other script as an RPC server (XMLRPC), and perform RPC calls