SO的程式員你好,
我正在為套接字制作一個 C# 介面,
介面是用 C# 制作的,但負責實際套接字部分的代碼是用 Python 撰寫的,因為用 C# 撰寫會很瘋狂,
我使用了一些 ironPython 來執行 python 代碼:
var engine = Python.CreateEngine();
engine.ExecuteFile(""); //directory is inside the quotes
但我需要傳遞一些值(IP 和所有爵士樂)
有誰知道怎么做?
我查看了如何使用 IronPython 將引數傳遞給 Python 腳本,實作起來太難了,所以請不要問該執行緒是否回答了我的問題
uj5u.com熱心網友回復:
您可以將資料作為字串存盤在 c 中的某個檔案中,并且您可以在 python 中使用一個執行緒不斷查找資訊。如果某個關鍵字與它一起傳遞,它就會知道資訊何時存盤在檔案中。例如(如果您使用的文本檔案的位置名為 location)
File.WriteAllText(location, IPAdress "[IP]");
這是搜索它的代碼
foreach(string datainfo in File.ReadAllText(location).Split(Convert.ToChar("\n"))
{
if(datainfo.Contains("[IP]")
datainfo.Replace("[IP]","");
string Ip = datainfo;
}
我不知道如何處理 python 中的檔案,但是上面 csharp 代碼的 python 等效代碼應該可以作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/402098.html
上一篇:客戶端和服務器都處理一個檔案
