Python Forum
Calling C functions with PyObjects
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling C functions with PyObjects
#1
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.
Reply
#2
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.
Reply
#3
Can I use PyImport_Import to import a C file, then call a C function within that file with a PyObject?
Reply
#4
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.
Reply
#5
Example:
File1.c:
Init Pyobjects
Call File2 Function:

File2.c:
Some function.
Reply
#6
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.
Reply
#7
I have created a shared library. Can I then call those function in the library with PyObjects?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling functions by making part of their name with variable crouzilles 4 746 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  Calling functions from within a class: PYQT6 Anon_Brown 4 3,641 Dec-09-2021, 12:40 PM
Last Post: deanhystad
Question trouble with functions "def", calling/defining them Duck_Boom 13 4,231 Oct-21-2020, 03:50 AM
Last Post: Duck_Boom
  calling os functions not in module os Skaperen 2 2,588 Nov-10-2018, 01:54 AM
Last Post: Skaperen
  Trouble calling functions in main function RedSkeleton007 6 4,992 Nov-11-2017, 01:22 PM
Last Post: sparkz_alot
  Calling functions from another file jp2017 11 30,404 Oct-11-2017, 10:58 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020