0

I have code with many functions and main, when I am trying to run the code it's not working and showing like it run successfully. When I am run the debugger it's show me that it run only on the functions' names. so I am pretty sure the problem it's with the main. how can i solve it?

ariel20
  • 15
  • 10

1 Answers1

3

main() is not run implicitly (like in C or Java). In Python you have to explicitly call if you want your code to run.

def main():
    some_code()

if __name__ == "__main__":
    main()  # actually run main

Note that main does not have to be named main - it may be arbitrary named function. Moreover, code to run does not even have to be enclosed in any function. Consider file with content like that:

print "abc"

It'll simply print "abc" on standard output.

Łukasz Rogalski
  • 22,092
  • 8
  • 59
  • 93