0

Got this code in C#:

using System;

public class Listener{
   public static void Main(){
      Console.WriteLine("Hello world...");
      Console.ReadLine();
   }
}

Tried to translate it to IronPython and compile it by ipy pyc.py /main:Listener.py Listener.py /target:exe:

from System import *

class Listener:
    def Main(self):
        Console.WriteLine("Listening")
        Console.ReadLine()

When I try to run it by ipy or directly the exe, nothing happens.

What is the problem?

2 Answers 2

2

Python does not have/require a main method (by convention entry point).

You just have to call the Main-method at the end of your .py if you want to run it.

Listener().Main()

Another way to do this is to check if you are the primary/first python file to run. This allows you to create modules which can be used/imported or run standalone:

if __name__ == '__main__':
    Listener().Main()
Sign up to request clarification or add additional context in comments.

Comments

0
from System import *

class Listener:
  def Main(self):
    Console.WriteLine("Listening")
    Console.ReadLine()

if __name__ == '__main__':
  Listener().Main()

or, more Pythonic

if __name__ == '__main__':
  raw_input('Listening')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.