2

I have a model built in python. I have a C# Web application in which i want to score the records on demand. I am looking into option available to do so. What are my options to do integrate python scoring code in .Net (I really dont want to host a separate webservice)

PS: I am aware of the duplicate. DUPLICATE The question is 2 years old. I tried reaching out to people who answered the question, but i havent got a response to my comments.

Community
  • 1
  • 1
Bhanu Kaushik
  • 876
  • 6
  • 25

1 Answers1

0

Many programming languages allow to invoke the process. So this can be one of your options. Read this question with an excellent answer (whose code I took) for more details:

private void run_cmd(string cmd, string args)
{
     ProcessStartInfo start = new ProcessStartInfo();
     start.FileName = "my/full/path/to/python.exe";
     start.Arguments = string.Format("{0} {1}", cmd, args);
     start.UseShellExecute = false;
     start.RedirectStandardOutput = true;
     using(Process process = Process.Start(start))
     {
         using(StreamReader reader = process.StandardOutput)
         {
             string result = reader.ReadToEnd();
             Console.Write(result);
         }
     }
}
Community
  • 1
  • 1
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • 1
    I wouldn't say that the correct answer to "can I use X in Y" is "yes of course you can use python library X inside of c#, simply use subprocess!" – anthony sottile Aug 21 '15 at 05:45
  • Thanks for the response. Having a python engine in the application is a solution. However, I am looking for a less expensive apporach like ironpython etc. I am not sure if scikit is supported yet. – Bhanu Kaushik Aug 21 '15 at 20:20