problem using C-bindings

Jack Diederich jack at performancedrivers.com
Thu Aug 19 17:45:45 EDT 2004


On Thu, Aug 19, 2004 at 10:32:15PM +0200, eq wrote:
> Hi,
> 
> I'm trying to create a program(written in C) that does the following
> things using embedded Python:
> 1. Create a module(say, "MyModule")
> 2. Create a class in that module(say, "MyClass")
> 3. Create a function in that module(say, "MyFunction")
[snip]
> 	class_dict=PyDict_New();
> 	class_name=PyString_FromString("MyClass");
> 	class=PyClass_New(NULL,class_dict,class_name);
> 	PyDict_SetItemString(module_dict,"MyClass",class);
[snip]

Take a look at Modules/xxsubtype.c in the source distribution.
It is an example of how to subtype a builtin.  xxmodule.c shows
how to make a class from scratch.  Both are out of date but a good
sarting spot.

You could also give Pyrex a try, it makes it easier to write just
a hot function or two of a class in C.  I like it to prototype C versions
of hotspot functions (but then do the final version 'by hand').

-Jack



More information about the Python-list mailing list