Python main function -


this question has answer here:

i came across line in python:

def somefunc:     [...]  if __name__ == '__main__':     somefunc 

i don't understand "if __name ..." does.

suppose have:

if __name__ == '__main__': main()  #this code find main 

so similar main() function in c/c++, gets executed before other function?

you can think main() in c or begin { } block in perl.

when run code using python file1.py.

__name__ in file1.py equal '__main__', in other files imported file1.py, variable else.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -