我找到了一个类似的方法,用它调用方法要容易得多。
C#代码如下:IDictionary options = new Dictionary();
options["Arguments"] = new [] {"C:\Program Files (x86)\IronPython 2.7\Lib", "bar"};
var ipy = Python.CreateRuntime(options);
dynamic Python_File = ipy.UseFile("test.py");
Python_File.MethodCall("test");
因此,基本上我提交了字典,其中包含要在python文件中定义的库路径。
所以PYthon脚本如下所示:#!/usr/bin/python
import sys
path = sys.argv[0] #1 argument given is a string for the path
sys.path.append(path)
import httplib
import urllib
import string
def MethodCall(OutputString):
print Outputstring
所以方法调用现在更容易从C#
而且传递的参数保持不变。
也可以使用此代码获取自定义库文件夹
对于Python文件,如果您在网络中工作的话,这是非常好的
有很多不同的电脑