Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
define a main()
#2
something like this
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.
Reply


Messages In This Thread
define a main() - by Pedroski55 - Oct-07-2017, 08:59 AM
RE: define a main() - by buran - Oct-07-2017, 09:11 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020