// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using Python.Runtime; public class Test { public static void Main(string[] args) { Console.WriteLine("Starting"); PythonEngine.Initialize(); using(Py.GIL()) { PythonEngine.Exec("print('Hi from python')"); dynamic v = PythonEngine.Eval("2 * 2 + 3 * 3"); Console.WriteLine(v); using(PyModule scope = Py.CreateScope()) { int a = 123; int b = 456; scope.Set("a", a.ToPython()); scope.Set("b", b.ToPython()); dynamic c1 = scope.Eval("a + b"); Console.WriteLine(c1); scope.Exec("c = a + b"); dynamic c2 = scope.Get("c"); Console.WriteLine(c2); } dynamic test = Py.Import("test"); test.hi(3); } PythonEngine.Shutdown(); Console.WriteLine("Finished"); } }