Python main function -
this question has answer here:
- what if __name__ == “__main__”: do? 18 answers
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
Post a Comment