skywalker007
skywalker007

Reputation: 31

Source code for os.remove() in python

Where is the source code for os.remove() in python? In the following file "https://github.com/python/cpython/blob/master/Lib/os.py", some functions of "os" are given but I couldn't find the definition for "remove".

Basically I want to check how remove() is implemented in python.

Upvotes: 2

Views: 1018

Answers (1)

kichik
kichik

Reputation: 34744

It's here for POSIX:

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

At the top of os.py you see it imports a module named posix if it's running on POSIX:

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

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

It is a built-in module defined at the bottom of 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);
// ...

Upvotes: 2

Related Questions