使用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