On 22/10/2012 12:45, Matthew Ngaha wrote:
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?
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
See this http://docs.python.org/tutorial/modules.html specifically
section 6.1.1. "Executing modules as scripts".
--
Cheers.
Mark Lawrence.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor