Python C module questions

Thomas Heller theller at python.net
Thu Sep 1 21:00:54 CEST 2005


Robert Kern <rkern at ucsd.edu> writes:

> jeremy.d.brewer at gmail.com wrote:
>> Hi,
>> 
>> I'm rather new to Python, and I've just written my first Python C
>> module.  I was wondering if some more experience Pythonista would look
>> over what I've written and given me some pointers (or find some bugs).
>> I had a few questions while writing this as well.
>> 
>> Also, I know that there are much better ways to compute nearest
>> neighbors than the brute force n^2 method, but this is plenty fast for
>> this application (at least the C version is).

You should give up C with a dumb algorithm running at fast speed.
Implement a better algorithm in Python, maybe you can even outperform
the dumb code.

>> 1.  How do I add docstrings to my module?
>
> You mean a docstring on the module object itself? In initmodule() make a
> string object with the contents of the docstring and assign it to
> module.__doc__ . There might be a more idiomatic way, but I can't think
> of it without trawling through the docs.

Use Py_InitModule3() instead.

Thomas



More information about the Python-list mailing list