0
IronPython的將直接從C#運行不Process.Start
的IronPython如何通過命令行參數的腳本文件從C#中
腳本文件我想加載需要一個參數(filename
), 你怎麼寫出來在C#中?
注意:這將有望成爲將Python腳本轉換爲使用GUI選擇文件的Windows GUI應用程序的轉換。
IronPython的將直接從C#運行不Process.Start
的IronPython如何通過命令行參數的腳本文件從C#中
腳本文件我想加載需要一個參數(filename
), 你怎麼寫出來在C#中?
注意:這將有望成爲將Python腳本轉換爲使用GUI選擇文件的Windows GUI應用程序的轉換。
假設一個腳本generator.py
可能看起來像
import sys
fileName = sys.argv[0]
print "working on", fileName
的IronPython的引擎,可以在C#/。NET通過
var options = new Dictionary<string, object>();
options["Arguments"] = new[] { @"/somefile.dat" };
var engine = Python.CreateEngine(options);
var runtime = engine.Runtime;
var scope = engine.CreateScope();
var script = engine.CreateScriptSourceFromFile(@"generator.py");
script.Execute(scope);
導致輸出working on /somefile.dat
主辦。
你能說清楚你的問題嗎?你想從C#中運行IronPython並傳遞一個參數? – Mathemats
如果速度不是主要問題,那麼爲什麼不用params寫一個帶有c#的文件,關閉文件,然後讓你的python腳本從同一個文件中讀取para。 – calmond
[腳本參數和嵌入式IronPython]的可能重複(http://stackoverflow.com/questions/1601364/script-arguments-and-embedded-ironpython) –