使用IronPython2.6
引用:
代碼:
using System;
using System.Collections.Generic;
using System.Text;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace IronPython
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Loading sayHello.py...");
var ipy = Python.CreateRuntime();
dynamic mock = ipy.UseFile("sayHello.py");
Console.WriteLine("sayHello.py loaded!");
string ss = mock.welcome(" cs");
Console.Write(ss);
Console.ReadLine();
}
}
}
而關鍵文件sayHello.py必須要放在項目/bin/debug目錄下
sayHello.py的內容:
def welcome(x):
return "Hello world"+x