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 -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -