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?
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.
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: