+ 1

__name__ (python)

Hi everyone, Does anybody have an easy explanation of what is __name__ == ‘__main__’ : Sorry I’m not a smart as you :) Just don’t get it

21st Feb 2018, 5:23 PM
Denis
Denis - avatar
5 Respuestas
+ 2
For simplify __name__ represent the name of program for example "code". "__main__" is as called the program when he is executed in him same. Example: The program name bellow is "code" ,that is , __name__ == "code" of indirectly way ,but when call the command "print(__name__)" he gives back "__main__" because "code" is be executed directly and not indirectly per an import for example. https://code.sololearn.com/cblxSWcreU6O/?ref=app
21st Feb 2018, 10:45 PM
J G
J G - avatar
+ 1
basically __name__ represent the name of program for example: "myfirstprogram" This if program was imported ,but case you will be execute "myfirstprogram" directly ,he called "__main__" ,this is general used in condition for execute an action ,case the program not will be imported ,but can be appliqued in other cases. Example: <--CODES--> First import Second Second if __name__ == "__main__": print("Is main !") else: print("Imported !") <--EXECUTE--> First Imported ! Second Is main ! • Sorry by some error in answer with English ,my English is bad.
21st Feb 2018, 6:03 PM
J G
J G - avatar
+ 1
which part ? Of __name__ or "__main__".
21st Feb 2018, 6:07 PM
J G
J G - avatar
0
Still don’t get it
21st Feb 2018, 6:05 PM
Denis
Denis - avatar
0
Both
21st Feb 2018, 7:41 PM
Denis
Denis - avatar