[ale] [OT] Calling Python from C ABI compatible languages

Joe Knapka jknapka at kneuro.net
Thu Sep 23 18:43:45 EDT 2010


Hi Michael,

It's not really *that* hard to call Python from C:

#include <Python.h>

int
main(int argc, char *argv[])
{
  Py_Initialize();
  PyRun_SimpleString("from time import time,ctime\n"
                     "print 'Today is',ctime(time())\n");
  Py_Finalize();
  return 0;
}


That's from the Python 2.7 docs: http://docs.python.org/extending/embedding.html

Your other option, of course, is to fork&exec to run bzr commands,
which on the surface seems less-than-ideal.  OTOH I expect bzr will be
mostly network-I/O-bound, so it may not make any difference that the
user would notice.

You may be interested in Pyrex and/or psyco, which are various forms
of compiler for Python code.  I doubt either of them would make your
life any easier than PyRun_SimpleString(), though.

If you are planning to keep a lot of state in your C code that Python
is going to need access to, then I suspect you may be suffering from a
form of "hammer/nail disorder".

-- JK


On Thu, Sep 23, 2010 at 1:05 PM, Michael B. Trausch <mike at trausch.us> wrote:
>
[snip]


More information about the Ale mailing list