Tutorial by Examples

The following C source file (which we will call hello.c for demonstration purposes) produces an extension module named hello that contains a single function greet(): #include <Python.h> #include <stdio.h> #if PY_MAJOR_VERSION >= 3 #define IS_PY3K #endif static PyObject *hell...
Pass an open file object from Python to C extension code. You can convert the file to an integer file descriptor using PyObject_AsFileDescriptor function: PyObject *fobj; int fd = PyObject_AsFileDescriptor(fobj); if (fd < 0){ return NULL; } To convert an integer file descriptor back ...
This is a basic example of a C Extension using C++ and Boost. C++ Code C++ code put in hello.cpp: #include <boost/python/module.hpp> #include <boost/python/list.hpp> #include <boost/python/class.hpp> #include <boost/python/def.hpp> // Return a hello world string. st...

Page 1 of 1