Oct-07-2017, 09:11 AM
something like this
it allows to import your module in other modules, but if executed as a python file what is in the body will be executed, e.g. call to main or call of foo and bar in the second example.
def foo(): print('this is output from function foo') def bar(): print('this is output from function bar') def main(): # this function can be names as you want foo() # call function foo bar() # call function bar if __name__ == '__main__': main()
def foo(): print('this is output from function foo') def bar(): print('this is output from function bar') if __name__ == '__main__': foo() bar()note the line
if __name__ == '__main__':
it allows to import your module in other modules, but if executed as a python file what is in the body will be executed, e.g. call to main or call of foo and bar in the second example.