[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] [OT] Calling Python from C ABI compatible languages
- Subject: [ale] [OT] Calling Python from C ABI compatible languages
- From: jknapka at kneuro.net (Joe Knapka)
- Date: Thu, 23 Sep 2010 16:43:45 -0600
- In-reply-to: <1285268740.5352.22.camel@mbt-desktop>
- References: <1285268740.5352.22.camel@mbt-desktop>
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]