I haven't done much python - coming from a C/Java background - so excuse me for asking such a simple question. I am using Pydev in Eclipse to write this simple program, and all I want it to do is to execute my main function:
class Example():
if __name__ == '__main__':
Example().main() <----- What goes here?
def main(self):
print "Hello World!
That is what I have now. I have also tried
self.main()
and
main()
and
main(self)
none of which work. What am I missing?
main? If yes, that suggests to me thatmaindoesn't belong in this class. If no, that suggests to me that you're not really using the class as a class.mainfunction at module scope. It calls other code, or creates the initial objects. Nothing calls it, and it doesn't manipulate any "internal state" the way the methods of normal classes do. But maybe what you're doing is more appropriate for your use case; it's hard to say without seeing your code. Just don't blindly use Java'smainmethod idiom in Python if it doesn't actually help you! I findmainis usually much more like a procedure than it is like a method.