I am building a system which is much like Mathwork's Simulink or Tanner-Spice where the user defines a function using available operators. Then I need to run that function and return the response to the user. I am using Javascript for UI interaction. Internally, the user-defined function (UDF) is captured as a JSON and passed to a Python server that parses this JSON.
My problem is, how to I now run this UDF? I am not worried about malicious users exploiting this ability to hack, because all my users are trusted ones.
One way I thought was to write the UDF onto disk as a python script and then running the commands.getstatusoutput(). The problem here is that the function might expect several inputs, and it is not possible to pass those.
What I am looking for is the ability to dynamically loading a new python file and its functions, and be able to call those.
Found a blog post that explains how to do this. I guess the problem was me not using the right keywords to search.
Anyway, David Janes' blog here explains how to dynamically load a python script.
I would still invite you guys to comment and propose if there are better ways of doing what I wanted.
Thanks, Nik