4
$\begingroup$

I am new to Mathematica and I need to interface with a Python code that I have. Basically, I have a Mathematica package (.m) with a bunch of complicated functions. I want to use some code from python to call some functions from the .m file. Is it possible?

I so the solution given in How to use Mathematica functions in Python programs?. However, I need the functions from the .m file, not the built in Mathematica functions.

Thanks!

$\endgroup$
  • $\begingroup$ Use Python to construct a .m file which includes everything you need to run the first desired function in the .m file. Run that file in batch mode from Python to get the result. Repeat all this for the next next function. Repeat all this for the next function. $\endgroup$ – Bill Mar 23 '16 at 2:15
  • $\begingroup$ Hello @Bill, I'm not sure how to do that... Can you provide an example? Thanks! $\endgroup$ – Jemme Mar 23 '16 at 10:10
  • $\begingroup$ Here are the contents of my MMAinBatchMode.bat "C:\Program Files\Wolfram Research\Mathematica\10.2\math" < in.txt > out.txt and here are the contentx of my in.txt file Print[2^100]; and here are the generated out.txt contents Mathematica 10.2.0 for Microsoft Windows (64-bit) Copyright 1988-2015 Wolfram Research, Inc. In[1]:= 1267650600228229401496703205376 In[2]:= Now you just need to use Python to generate your own in.txt file to calculate the result you want and use Python to run that bat file. And use Python to extract your result from out.txt Is that a clear enough example? $\endgroup$ – Bill Mar 26 '16 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.