0

I was wondering if it is possible to call a python file in an SML program, and if so how can you do it? I have tried researching how to do this, but have only found documentation on how to call other SML files.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
arizq29
  • 11
  • 5

1 Answers1

4

I think OS.Process.system "python myscript.py" should work. See: http://sml-family.org/Basis/os-process.html

Alejandro C.
  • 3,771
  • 15
  • 18
  • I am receiving a tycon mismatch error when I try to implement this. I added my sml code as well as the error and the method in python I am trying to call. Can you see where I went wrong? – arizq29 Apr 25 '17 at 15:35
  • @arizq29, I suggest opening a new question that contains the complete SML code you're using too. – Alejandro C. Apr 25 '17 at 15:49
  • My entire SML code is contained in the link above. It is very short, I am just trying to call a method from a python file I wrote in SML. The link also includes the error I am receiving. The SML code is below the error. – arizq29 Apr 25 '17 at 17:02
  • @arizq29 why are you doing a recursive call? The problem is that you're taking the return value of `interpreter` (which is the return value of `OS.Process.system`, which is `OS_Process.status`), binding it to `s`, and then trying to concatenate (`^`) `s` with a string. That's the type mismatch. – Alejandro C. Apr 25 '17 at 19:35
  • Ok, so how would I go about calling the function in python using the arguments received from the SML function then? Would I just get rid of the concatenation so its OS.Process.system ("python interpreter.py")? That allows the sml program to compile and returns me this `val interpreter = fn : string * string -> Word32.word val it = () : unit` My program in python should output a text file, so is Word32.word the output I should expect? – arizq29 Apr 25 '17 at 20:06
  • Again, a separate question would be better. `OS.Process.system("python interpreter.py " ^ infile ^ " " ^ outfile)` is how you'd pass your arguments. Then the output is just a status (*not* stdout). Presumably your output will be at `outfile`. – Alejandro C. Apr 25 '17 at 20:15