繁体   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