Python C module questions

jbrewer jeremy.d.brewer at gmail.com
Thu Sep 1 23:51:32 EDT 2005


>You probably shouldn't post such large pieces of code to the list.

OK.

>You mean a docstring on the module object itself?

Actually, I meant docstrings to the module and the functions, objects,
methods, whatever else in the module.  My code was derived from the
Python Cookbook, which left that part out (rather important for
building real C modules).

>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.

That would be the next step if I needed even more speed, but the better
algorithm here would be to use KDTrees, which would be overkill (and
would require lots of development time).  The C brute force
implementation runs plenty fast for me.  It took only took a few hours
to implement and yielded a factor of 7 performance increase.  I was
mostly interested in feedback on whether I had done things in a
properly efficient way (there are so many Python list / tuple /
sequence functions).  I also find it hard to believe that there's no
standard Python function for converting sequences of one object to
arrays in C (a friend mentioned that Ruby's C API has this).

Another question: how does the distutils package handle version
upgrades?  Say for example I find some bugs in my C code and need to
recompile it, will it just overwrite what's present in the
site-packages directory?

Jeremy




More information about the Python-list mailing list