[Tutor] Which is better Practice and why

Matthew Ngaha chigga101 at gmail.com
Mon Oct 22 13:45:16 CEST 2012


In many of the tutorial examples ive come across, the main code's program
is never at the top level, but always in a function of some sort. i
understand why but, there is always a different way used to access the main
code, i want to know which is the best.


main()
     main's code

#top level
main()

they call the main program by simply calling the main function. I've also
seen a more complcated:

if __name__ == '__main__':
    main()

the 2nd one usually includes a lot more code then i showed. can you please
tell me why different methods are used to access the main code? is it just
preference or is one way actually better coding practice?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121022/7881d21d/attachment.html>


More information about the Tutor mailing list