Reputation: 3322
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?
Upvotes: 0
Views: 537
Reputation: 6211
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()
Upvotes: 2
Reputation: 36862
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')
Upvotes: 0