摘要: 考慮在現(xiàn)有的C#的開發(fā)結(jié)構(gòu)下, 添加Python調(diào)用模塊. 基本思想是學習和借鑒已有的開發(fā)經(jīng)驗, 在實踐中逐步添加新的應用. 基本目的是C#調(diào)用Python腳本校读、實現(xiàn)與Mysql數(shù)據(jù)庫的交互弥锄、C#從數(shù)據(jù)庫中讀取Python執(zhí)行結(jié)果丧靡、Python腳本自動上傳.?
準備工作
1. 下載和安裝IronPython
2. 在Bin文件夾下添加引用IronPython.dll和Microsoft.Scripting.dll(注意版本)
3. C#網(wǎng)站腳本調(diào)用
C#部分
ScriptRuntime pyRunTime = Python.CreateRuntime();
dynamic obj = pyRunTime.UseFile("E:\\Safety\\hello.py"); //絕對路徑
var result = obj.welcome("Nick");
this.Label1.Text = result;?
Python部分
def welcome(name):
return "hello" + name + '123'
圖1 運行結(jié)果示意圖
參考文獻
1. http://www.tuicool.com/articles/beeI3aY