Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the entry point to python source code

Tags:

python

cpython

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.

like image 491
InAFlash Avatar asked Jun 06 '18 07:06

InAFlash


2 Answers

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.

like image 186
Paul Hankin Avatar answered Oct 05 '22 23:10

Paul Hankin


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
like image 25
balu Avatar answered Oct 05 '22 23:10

balu