Putting the main program in a main function
ast
nomail at invalid.com
Mon Sep 14 03:13:47 EDT 2015
Hi
I saw here http://inventwithpython.com/pygame/chapter3.html
a program where the main program is put in a function.
So the structure is:
def main():
main code here
def f1():
function 1 code
def f2():
function 2 code
......
if __name__ == '__main__':
main()
The author says that with this structure there are no
global variables (except when using "global' keyword)
and that the program can be loaded as a module without
be ran to test the function in the python shell.
is it advised to always write programs like that ?
thx
More information about the Python-list
mailing list