Of course, I can use the this code:
session = StartExternalSession["Python"];
mmaVar1 = ExternalEvaluate[session, "a=[3,6,4];a"]
{3, 6, 4}
Then I can get a MMA variable mmaVar1
, its name is assigned by Python. But I have to say it hard to write python code in a string line. So I like typing a > key into DefaultPythonSession:
But how to get the value of a
in the DefaultPythonSession and assign to a MMA variable? This is my current method:
Find the order of the DefaultPythonSession by
ExternalSessions[]
:Then
mmaVar2 = ExternalEvaluate[ExternalSessions[][[2]], "a"]
Dirty solution...
SelectFirst[ExternalSessions["Python"], #["Name"] === "DefaultPythonSession" &]
make it less dirty ;) $\endgroup$ExternalEvaluate`GetDefaultExternalSession["Python"]
$\endgroup$