I hear D is link-compatible with C. I'd like to use D to create an extension module for Python. Am I overlooking some reason why it's never going to work?
Most of the Python Libraries are written in the C programming language.
Any code that you write using any compiled language like C, C++, or Java can be integrated or imported into another Python script. This code is considered as an "extension." A Python extension module is nothing more than a normal C library. On Unix machines, these libraries usually end in . so (for shared object).
Python code can make calls directly into C modules. Those C modules can be either generic C libraries or libraries built specifically to work with Python.
You'll need a file called setup.py to install your application. For this tutorial, you'll be focusing on the part specific to the Python C extension module.
Writing a simple C extension module directly using Python’s extension API and no other tools. It is straightforward to make a handcrafted extension module for a simple C code. But first, we have to make sure that the C code has a proper header file. The header would correspond to a library that has been separately compiled.
1. Extending Python with C or C++ ¶ It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can’t be done directly in Python: they can implement new built-in object types, and they can call C library functions and system calls.
It is quite easy to add new built-in modules to Python, if you know how to program in C. Such extension modules can do two things that can’t be done directly in Python: they can implement new built-in object types, and they can call C library functions and system calls.
If you want to raise Python exceptions from your C extension module, then you can use the Python API to do so. Some of the functions provided by the Python API for exception raising are as follows: Takes two arguments: a PyObject * type argument specifying the type of exception, and a custom message to display to the user
Wait? Something like this http://www.dsource.org/projects/pyd (previously http://pyd.dsource.org/)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With