python 源代码的入口点是什么
what is the entry point to python source code
我正在尝试了解 python 的工作原理。因此,我使用了官方 python 存储库的分支,可在以下 Link 获得。我是初学者 c 程序员。但是,我知道 main 是应用程序的入口点。由于python写在c, c++
中,main
是入口点,谁能帮我看看哪个文件有main
功能。所以,当我 运行 python.exe
时,首先执行哪个函数获取所有命令行参数?
注意:我不是在请求 python 程序的入口点。我知道编译器只是开始逐行执行。我想知道的是,当我们 运行 一段代码时,python 源代码中的哪个函数实际上采用整个 python 代码解释它并给出结果。
它在文件 Programs/python.c
中。 https://github.com/python/cpython/blob/master/Programs/python.c
如您所见,它唯一做的就是调用另一个函数,您可以在此处找到该函数。 https://github.com/python/cpython/blob/master/Modules/main.c
解析命令行参数的代码在这里:https://github.com/python/cpython/blob/master/Modules/main.c#L2601
请注意 github 具有搜索功能,因此您可以搜索 "main" 或“_Py_UnixMain”并查找参考文献。
我想你要找的是 this file:
/* 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
我正在尝试了解 python 的工作原理。因此,我使用了官方 python 存储库的分支,可在以下 Link 获得。我是初学者 c 程序员。但是,我知道 main 是应用程序的入口点。由于python写在c, c++
中,main
是入口点,谁能帮我看看哪个文件有main
功能。所以,当我 运行 python.exe
时,首先执行哪个函数获取所有命令行参数?
注意:我不是在请求 python 程序的入口点。我知道编译器只是开始逐行执行。我想知道的是,当我们 运行 一段代码时,python 源代码中的哪个函数实际上采用整个 python 代码解释它并给出结果。
它在文件 Programs/python.c
中。 https://github.com/python/cpython/blob/master/Programs/python.c
如您所见,它唯一做的就是调用另一个函数,您可以在此处找到该函数。 https://github.com/python/cpython/blob/master/Modules/main.c
解析命令行参数的代码在这里:https://github.com/python/cpython/blob/master/Modules/main.c#L2601
请注意 github 具有搜索功能,因此您可以搜索 "main" 或“_Py_UnixMain”并查找参考文献。
我想你要找的是 this file:
/* 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