I am familiar with java but new to python and I wanted to know whether this piece of code is same as the main method in java if __name__ == '__main__'. Do all the python class need this code to execute. what if I did not have this code in my .py file. Will it throw any error message
Asked
Active
Viewed 47 times
0
-
No, it is not the same thing, but it can help you run code only if the module is used as the main entry point. Thus it is *related*. – Martijn Pieters Oct 09 '17 at 07:50
-
When does the __name__ field gets initialized and how?? – Oct 09 '17 at 07:54
-
https://docs.python.org/3/tutorial/modules.html – cdarke Oct 09 '17 at 08:06