Python Script can be called from C# with using IronPython.
Python Script
def hello(name) :
return "Hello! " + name
C# code
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
void HelloPython
{
ScriptEngine python = Python.CreateEngine();
string path = @"C:\scripts\hello.py";
dynamic script = python.ExecuteFile(path);
Console.WriteLine(script.hello("John"));
}
> Hello! John
This can be used in cshtml view files like this:
@using IronPython.Hosting;
@using Microsoft.Scripting.Hosting;
@{
ScriptEngine python = Python.CreateEngine();
string path @"C:\scripts\hello.py";
dynamic script = python.ExecuteFile(path);
string msg = script.hello("John");
}
<h2>@msg</h2>