I'm trying to make a wrapper REPL for the free Wolfram Engine (on Cygwin, there are a bit of I/O issues) in Python, so I am using the wolframclient library. However, whenever I use D[x^2,x] as a test, instead of returning 2x, it gives Times[2, Global`x]. My code is below:
#!/usr/bin/env python
from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wlexpr
import readline
count=0
with WolframLanguageSession('/cygdrive/c/Users/School/Downloads/Mathematica/WolframKernel.exe') as session:
while True:
expr=input('In['+str(count)+']:= ')
print('Out['+str(count)+']= '+str(session.evaluate(wlexpr(expr))))
count+=1
Edit: ToString[expr,InputForm] helped with the expression, but is there a way to get % to expand to the last expression?