I have to evaluate (millions of) Python expressions e.g. (int(a) >> 8 == 4) and b
in my OCaml program. There is pycaml but I failed to get it working.
So I turned to another idea: control the input/output of Python interpreter directly.
Ideally I would like to intercept both the input/output of the interpreter itself.
By sending a = 3 b = 5 a > b to the interpreter, I would then be able to get the result False, as if I have done this by keyboard..
>>> a = 3
>>> b = 5
>>> a > b
False
>>>
However, my code doesn't working as expected (while the same code worked for some interactive program)
let (readme, writeme) = Unix.open_process "python -u";;
let _ = output_string writeme "3 + 5\n" in
let _ = flush writeme in
let result = input_line readme in
print_endline result;;
I tried changing 3 + 5\n to print 3\n, but it still hangs at input_line.
Is there any better way to do this? I would need to evaluate quite a lot of
expressions, so I don't really want to do this via a temp file. Any help appreciated,
Thanks.