i am trying to understand how python works. so, i took fork of official python repository which is available at the following Link. I am a beginner c programmer. but, i understand that main is the entry point to the application. Since python is written in c, c++
, for which main
is the entry point, can anyone help me which file has the main
function. so, when i run python.exe
, which function is first executed taking all the command line arguments?
NOTE: i am not asking for an entry point to a python program. I know compiler just starts executing line by line. What i want to know is, when we run a code, which function in python source code actually takes the entire python code interprets it and give a result.
It's in the file Programs/python.c
. https://github.com/python/cpython/blob/master/Programs/python.c
As you can see, the only thing it does is call another function, which you can find here. https://github.com/python/cpython/blob/master/Modules/main.c
The code that parses command-line arguments is here: https://github.com/python/cpython/blob/master/Modules/main.c#L2601
Note that github has a search facility, so you can search for "main" or "_Py_UnixMain" and find references.
I suppose it is this file that you're looking for:
/* Minimal main program -- everything is loaded from the library */
#include "Python.h"
#ifdef MS_WINDOWS
int
wmain(int argc, wchar_t **argv)
{
return Py_Main(argc, argv);
}
#else
int
main(int argc, char **argv)
{
return _Py_UnixMain(argc, argv);
}
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With