Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python with C
#1
i want to get started writing some code that involves C. one aspect i want to ask those here that mix Python and C. is it preferred to have C coded to work with the way Python stores values and objects or is it preferred to have Python code to work with the way C stores values and objects?

one project i have in mind takes a big application already written in C to which i want to add Python as a scripting language.

i also have a set of functions in C to do some complicated calculations where speed is a big requirement. but i would like for some Python code to use them.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Have you looked at the documentation already, specifically the pages on embedding and the C API?
Reply
#3
i reviewed it once, a log time ago, but not since then. out of that i acquired some understand of the level of potential difficulty involved. before going back, i want to have the perspective of know how it is typically used, and which direction of preference is involved in any efforts to make tools to ease the connection between Python and C. for example, would you code such tools more on the Python side or the C side?

edit:

i am not planning to or expecting to be contributing code to CPython.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
Many tools already exist to interface Python and C/C++ that may be easier to use than the raw CPython API. Explore the following non exhaustive list
  • cffi
  • ctypes
  • swig
  • pybind11
  • boost.python
  • PyBindGen
  • SIP
  • Cppyy
  • Shiboken
  • cython
  • numba
  • ...
Skaperen likes this post
Reply


Forum Jump:

User Panel Messages

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