I learnt that in Python, main method is neither the entry point , nor mandatory. From the top, execution will happen line by line. So, where exactly does the main method come in the flow ? Does it happen when it reaches line by line upto the main method line ? Thanks
There is no main method in Python. It is a procedural language with OO pretensions. So when you run a program: "python path/to/program.py", Python simply starts at the first executable statement in the file and works down.
Common practice, however, even when not using Python in OOP mode is to put the bulk of the procedural code in a function and then have the option to execute that function like so:
This technique is especially useful if you have a program module that's normally invoked from somewhere else, but you want to be able to run it independently as a unit test.
Science is the process of replacing what we "know" with what is TRUE. Politics, alas, often prefers to be the opposite.
Thanks.So does that mean that this main method (even if present) is like any other method and does not have any special meaning ? What does the third line( if statement) do and from where does the value of __name__ variable come from?
The link says that main is the name of scope.I was thinking that it is the name of function. Also, it seems that main has a special meaning. I will read more about this to understand these details but at this point of time I know that the effect of the below code is that it calls main if it is called as a scirpt and not so if it is imported.
What I understand is that main which is the function name can be anything as it is the name of function.However __main__ is having special meaning as when program is run as a script __name__ automatically gets popupated as __main__. I will play around this on an IDE to understand more on this.