-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Python has a convenient internal _PyImport_GetModuleAttrString(mod_name, attr_name)
helper function to import a module and get a module attribute. I propose to make this function public to be able to use it outside Python. I also propose to make its variant _PyImport_GetModuleAttr(mod_name, attr_name)
public (which takes objects rather than strings).
API:
PyObject* PyImport_ImportModuleAttr(PyObject *mod_name, PyObject *attr_name)
Import the module mod_name and get its attribute attr_name.
Helper function combining
PyImport_Import()
andPyObject_GetAttr()
. For example, it can raiseImportError
if the module is not found, andAttributeError
if the attribute doesn't exist.
API:
PyObject* PyImport_ImportModuleAttrString(const char *mod_name, const char *attr_name)
Similar to
PyImport_ImportModuleAttr()
, but names are UTF-8 encoded strings instead of Pythonstr
objects.
For example, PyImport_ImportModuleAttrString("sys", "argv")
gets sys.argv
. It's similar to from sys import argv
in Python.
The function is used by 24 C files in Python.
Links:
Vote:
UPDATE: Rename the functions from PyImport_GetModuleAttr[String]()
to PyImport_ImportModuleAttr[String]()
.