Python - google lesson - function call template

I watched several videos on YouTube from Google and in the main lessons showed how to create and call a function:

def main():
    print 'Hello'

if __name__ == '__main__':   # this is the boilerplate portion
    main()

Why do we need to take an additional step to create this template, if we can just look like this code:

def main():
    print 'Hello'

main()

The result will be the same without additional code.

-BK

+3
source share
2 answers

This is for testing purposes. Then you write a module that you can test in the name / main section and make sure that the code works correctly. But when you call it from another module that you check in this section, it will not ring.

+2
source

, , . "", .

0

All Articles