簡體   English   中英

將代碼從C#轉換為Python所需的幫助

[英]Help needed to convert code from C# to Python

您能否將此代碼從C#轉換為Python以在IronPython上運行?

我對Python沒有任何經驗。

using System;
using Baz;

namespace ConsoleApplication
{
  class Program
  {
    static void Main()
    {
        Portal foo = new Portal("Foo"); 
        Agent bar = new Agent("Bar");

        foo.Connect("127.0.0.1", 1234); 
        foo.Add(bar);

        bar.Ready += new Agent.ReadyHandler(bar_Ready);               
    }

    static void bar_Ready(object sender, string msg)
    {    
       Console.WriteLine(msg.body);  
    }
}
}

實例化不需要類型定義。 相同的方法,直接分配委托。 以前的答案是絕對正確的,你需要更多背景下,以C#應用程序“轉換”到Python; 它不只是語法。

foo = Portal("Foo")

bar = Agent("bar")

foo.Connect("ip", 1234)

foo.Add(bar)

bar.Ready = bar_Ready

def bar_Ready(sender, msg):

    print msg.body

或者,如果您真的很懶, 可以在開發人員融合中使用C#到Python的轉換器

萬一其他人有這個問題,SharpDevelop可以使用轉換工具在C#和IronPython,VB.NET或Boo之間進行轉換http://community.sharpdevelop.net/blogs/mattward/archive/2009/05/11/ConvertingCSharpVBNetCodeToIronPython.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM