VS2010 C# 调用Ironpython

使用IronPython2.6

image

引用:

VS2010 C# 调用Ironpython_第1张图片

代码:

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目录下

VS2010 C# 调用Ironpython_第2张图片

sayHello.py的内容:

def welcome(x):
  return "Hello world"+x

你可能感兴趣的:(String,C#,System,Class,2010)