Python Forum

Full Version: Calling C functions with PyObjects
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using Python3.6:
[jibarra@redsky ~]$ python3.6
Python 3.6.8 (default, Apr 25 2019, 21:02:35) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.


I am referencing:
https://docs.python.org/3.6/extending/em...-embedding

Is there a way to call a C function in the same file using PyObjects?

Please advise.

Thank you.
Can you explain the question? From the C file, you can call C functions as in any other C program. There is no problem at all.
Can I use PyImport_Import to import a C file, then call a C function within that file with a PyObject?
PyImport_Import() is only a way to run a python import statement from C. I think
PyRun_SimpleString("import foo");
is more or less equivalent to
name = PyUnicode_FromString('foo');
PyImport_Import(name);
although from my experience, calling the python import statement is more robust.
Example:
File1.c:
Init Pyobjects
Call File2 Function:

File2.c:
Some function.
If you want to call a function from another C file, I think you can simply compile the file as a shared library and link the library with your extension module.
I have created a shared library. Can I then call those function in the library with PyObjects?