1.C#调用python脚本里面的函数
C#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
{
void main()
{
var engine = IronPython.Hosting.Python.CreateEngine();
var scope = engine.CreateScope();
//engine.CreateScriptSourceFromString("print 'hello world'")
var source = engine.CreateScriptSourceFromFile("hello.py");
//设定dll文件所在的目录
engine.AddToPath(Application.StartupPath);
//给python脚本增加引用路径
//ICollection<string> Paths = engine.GetSearchPaths();
//Paths.Add("//Lib");
dynamic obj=source.Execute(scope);
//方法一
var say_hello = scope.GetVariable<Func<object>>("say_hello");
say_hello();
//方法二
try
{
obj.say_hello();