In Python, you can get the current file path with the __file__ attribute.
print(__file__)
How can I access this attribute from a Python C Extension? I tried the following code, but the attribute doesn’t exist.
if (PyObject_HasAttrString(module, "__file__")) {
PyObject *string = PyObject_GetAttrString(module, "__file__");
const char *path = PyUnicode_AsUTF8(string);
}