Dec 30, 2007
Dynamically generating object methods in Python
I have recently been working on an object-oriented wrapper for the Python bindings to my [libxtract][1] feature extraction library. I used SWIG to auto-generate the bindings, and SWIG generally does a great job. The problem is that the functions it generates follow the original C code quite precisely, and aren't very 'Pythonic'. I wanted to create a nice Python class to hide some of the nastiness of the auto-generated functions, but became slightly daunted by having to hand-code every method of the new Xtract class with 50 very similar methods! Instead I decided to take advantage of Python's support for [lexical closures][2] to auto-generate the methods from the libxtract function descriptors using a method factory. The concept works like this (I think this is a fairly common idiom in Python):
Posted at 13:36 |
Comments(0) |
Permalink |
Trackbacks(0) |
Tags: programming, Python |
add to del.icio.us
Oct 29, 2007
Getting Old screenlets to work with Screenlets >=0.0.10-3
The Old Screenlets updated bundle available from here, contains a number of very useful screenlets including a calculator and a conversion utility. However, some of these screenlets won't work correctly with recent versions of screenlets because event handling has been changed (improved). Below are some simple patches to get Calc and Convert working properly with Screenlets >=0.0.10-3.
Posted at 10:32 |
Comments(0) |
Permalink |
Trackbacks(0) |
Tags: Python |
add to del.icio.us
Oct 08, 2007
What I learned from Python that makes me a better programmer when I use C
Here is my response to this call for posts on the raganwald blog. A response from Ryan Ginstrom can be found here
Posted at 10:49 |
Comments(3) |
Permalink |
Trackbacks(0) |
Tags: C, languages, programming, Python |
add to del.icio.us
Oct 02, 2007
Assigning a python list to a C char ** using SWIG
Using a SWIG-generated interface it's straightforward to assign variables of type char * from a Python script to a C variable: the char * datatype is assumed to be a NULL terminated ASCII string and mapped accordingly. The situation is a little different for variables of type char **, commonly used for arrays of pointers to strings.
Posted at 18:04 |
Comments(0) |
Permalink |
Trackbacks(0) |
Tags: C, Python, swig |
add to del.icio.us

