Skip to main content
 首页 » 编程设计

python之python 中 os.remove() 的源代码

2024年09月07日10tuyile006

python 中os.remove() 的源代码在哪里?在下面的文件“https://github.com/python/cpython/blob/master/Lib/os.py”中,给出了“os”的一些功能,但我找不到“remove”的定义。

基本上我想检查 remove() 在 python 中是如何实现的。

请您参考如下方法:

它在这里用于 POSIX:

https://github.com/python/cpython/blob/69dccc397ad1522309f15e4d5e0afe68b782ba66/Modules/posixmodule.c#L4374

在 os.py 的顶部,如果它在 POSIX 上运行,您会看到它导入了一个名为 posix 的模块:

https://github.com/python/cpython/blob/master/Lib/os.py#L64

if 'posix' in _names: 
# ... 
    import posix 
    __all__.extend(_get_exports_list(posix)) 

它是定义在posixmodule.c底部的内置模块:

https://github.com/python/cpython/blob/69dccc397ad1522309f15e4d5e0afe68b782ba66/Modules/posixmodule.c#L13698

#define MODNAME "posix" 
 
// ... 
 
static struct PyModuleDef posixmodule = { 
    PyModuleDef_HEAD_INIT, 
    MODNAME, 
// ... 
}; 
 
// ... 
 
PyMODINIT_FUNC 
INITFUNC(void) 
{ 
// ... 
    m = PyModule_Create(&posixmodule); 
// ...