Skip to main content
refine the formula
Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44

Sorry, I was mistaken and did not remember that you want to use MMA from Python and not the other way round. ExternalEvaluate["Python", str] is a MMA command, not Python.

How to give MMA input from Python is described here: "https://reference.wolfram.com/language/workflow/EvaluateAWolframLanguageExpressionFromPython.html".

After starting Python, you execute in Python:

from wolframclient.evaluation import WolframLanguageSession

session = WolframLanguageSession()

from wolframclient.language import wlexpr

session.evaluate(wlexpr('myCommandString'))

from wolframclient.evaluation import WolframLanguageSession

session = WolframLanguageSession()

from wolframclient.language import wlexpr

session.evaluate(wlexpr('myCommandString'))

where myCommandString is the string with your Mathematica statements. E.g. in Python:

myCommandString="a=1;b=2;a+b"

myCommandString="a=1;b=2;a+b" 

Or if you want this on several lines:

myCommandString="a=1;"

myCommandString=myCommandString+"b=2;"

myCommandString=myCommandString+"a+b"

myCommandString="a=1;"

myCommandString=myCommandString+"b=2;"

myCommandString=myCommandString+"a+b"

hope this helps.

Sorry, I was mistaken and did not remember that you want to use MMA from Python and not the other way round. ExternalEvaluate["Python", str] is a MMA command, not Python.

How to give MMA input from Python is described here: "https://reference.wolfram.com/language/workflow/EvaluateAWolframLanguageExpressionFromPython.html".

After starting Python, you execute in Python:

from wolframclient.evaluation import WolframLanguageSession

session = WolframLanguageSession()

from wolframclient.language import wlexpr

session.evaluate(wlexpr('myCommandString'))

where myCommandString is the string with your Mathematica statements. E.g. in Python:

myCommandString="a=1;b=2;a+b"

Or if you want this on several lines:

myCommandString="a=1;"

myCommandString=myCommandString+"b=2;"

myCommandString=myCommandString+"a+b"

hope this helps.

Sorry, I was mistaken and did not remember that you want to use MMA from Python and not the other way round. ExternalEvaluate["Python", str] is a MMA command, not Python.

How to give MMA input from Python is described here: "https://reference.wolfram.com/language/workflow/EvaluateAWolframLanguageExpressionFromPython.html".

After starting Python, you execute in Python:

from wolframclient.evaluation import WolframLanguageSession

session = WolframLanguageSession()

from wolframclient.language import wlexpr

session.evaluate(wlexpr('myCommandString'))

where myCommandString is the string with your Mathematica statements. E.g. in Python:

myCommandString="a=1;b=2;a+b" 

Or if you want this on several lines:

myCommandString="a=1;"

myCommandString=myCommandString+"b=2;"

myCommandString=myCommandString+"a+b"

hope this helps.

Source Link
Daniel Huber
  • 56.3k
  • 2
  • 24
  • 66

Sorry, I was mistaken and did not remember that you want to use MMA from Python and not the other way round. ExternalEvaluate["Python", str] is a MMA command, not Python.

How to give MMA input from Python is described here: "https://reference.wolfram.com/language/workflow/EvaluateAWolframLanguageExpressionFromPython.html".

After starting Python, you execute in Python:

from wolframclient.evaluation import WolframLanguageSession

session = WolframLanguageSession()

from wolframclient.language import wlexpr

session.evaluate(wlexpr('myCommandString'))

where myCommandString is the string with your Mathematica statements. E.g. in Python:

myCommandString="a=1;b=2;a+b"

Or if you want this on several lines:

myCommandString="a=1;"

myCommandString=myCommandString+"b=2;"

myCommandString=myCommandString+"a+b"

hope this helps.