4

I have this notebook:

arg1 = "input.txt";
arg2 = "output.txt";
u1 = Import[arg1, "Table"];
u2 = u1(*extremely complicated and long chain of operations*);
Export[arg2, u2]

and I would like to run it in a Python program like this:

def run(arg1,arg2):
    my_mathematica_code(arg1,arg2)

for i in range(100):
    run("input{}".format(i), "output{}".format(i))

How can I do this? Preferably without GUI and several threads in parallel (I can use 4 cores in Mathematica).

Michael E2
  • 235,386
  • 17
  • 334
  • 747
Danvil
  • 1,505
  • 1
  • 10
  • 17
  • 1
    related - if you don't mind putting things into a function: http://mathematica.stackexchange.com/questions/4643/how-to-use-mathematica-functions-in-python-programs – Jonie Aug 20 '13 at 12:08
  • Does this also works for code in my notebook which lies at some arbitrary location on my machine? – Danvil Aug 20 '13 at 12:36
  • Why not open a connection to a kernel with subprocess.Popen? Then you can communicate with that via pipes. – b3m2a1 Mar 20 '18 at 04:06

0 Answers0